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