4
votes

I've been having an issue that I can't seem to fix

3 errors prohibited this user from being saved:

  • Email can't be blank
  • Password confirmation doesn't match Password
  • Password is too short (minimum is 8 characters)

I can't figure out how to get rid of the 3 error prohibited this user from being saved: All I want to display is the errors in bullets. Any ideas on how to go along with this? I'm using Devise, by the way.

3
What version of Rails are you using?Paul Oliver
Please don't post screenshots of text. Type it out, so we can all read it.meagar
There is text in the post. The main issue is stated in the post @meagarIdris
Going through the OPs posts it looks to be the latest @PaulIdris

3 Answers

4
votes

I can't figure out how to get rid of the 3 error prohibited this user from being saved

We override the devise helper to give us ultimate control over the errors we wish to show. Here is a helpful resource which shows you how to achieve this

--

Helper

As per the answer by Buck Doyle & the attached resource, you may wish to do this:

#app/helpers/devise_helper.rb
module DeviseHelper
  def devise_error_messages!
     resource.errors.full_messages.map { |msg| content_tag(:li, msg) }.join
  end
end

This will allow you to change your devise views to include the devise_error_messages! method:

#app/views/devise/registrations/new.html.erb
<%= devise_error_messages! %>
2
votes

The Devise error messages come from a call to devise_error_messages!, which lives in a helper in devise/app/helpers/devise_helper.rb. I found this out by running bundle open devise and looking at the views. The forms views call that helper method.

You could put this code in an initialiser to override it:

module DeviseHelper
  def devise_error_messages!
    return "" if resource.errors.empty?

    messages = resource.errors.full_messages.map { |msg| content_tag(:li, msg) }.join

    html = <<-HTML
    <div id="error_explanation">
      <ul>#{messages}</ul>
    </div>
    HTML

    html.html_safe
  end
end

If you compare to the original, you’ll see I just removed the code that constructs the general error message and the h2 that contains it.

Another option would be to duplicate the views outside of the gem, then you can customise them with more granularity. You would run this and then edit the generated views:

rails generate devise:views
0
votes

Honestly the cheapest way to do this (although not technically removing the header) is just to add the following in your CSS:

#error_explanation h2 {
  display: none;
}