The error forbade the user to save:

I have a problem that I cannot solve

3 errors did not allow this user to be saved:

  • Email address cannot be empty
  • Password confirmation does not match password
  • Password is too short (minimum 8 characters)

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

+4
source share
3 answers

I can’t understand how to get rid of 3 errors that this user has prohibited from saving

devise, , . , , .

-

Buck Doyle :

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

devise views, devise_error_messages!:

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

devise_error_messages!, devise/app/helpers/devise_helper.rb. , bundle open devise . .

, :

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

, , , , h2, .

, . , :

rails generate devise:views
+2

, ( ) CSS :

#error_explanation h2 {
  display: none;
}
0

Source: https://habr.com/ru/post/1541918/


All Articles