in my user edit page, there is a line as follows:
<%= devise_error_messages! %>
The problem is this does not output errors the standard way that the rest of the app does:
<% flash.each do |key, value| %>
<div class="flash <%= key %>"><%= value %></div>
<% end %>
My question is, how do I get the devise error message to work like the others that use the flash.each?
Thanks.
Admittedly, a bit hacky, but I'm using this helper (app/helpers/devise_helper.rb) to grab flashes and use those if set then default to
resource.errors
. This is just based on the helper that's in the devise lib.I solved this similarly to YoyoS, by creating an
app/helpers/devise_helper.rb
and placing this in it:Worked!
I'm using Devise in Rails 3 and your flash code is pretty much identical to what I've got. In my app, the code works as expected; i.e. Devise error messages are output with the rest of my flash messages:
Try out this exact code and see if it makes any difference - the different ID attribute may help.
Below solution works with latest devise as of now (4.1.1) and Rails 4.2.6. But is so simple that I don't see the reason why wouldn't it work 10 years from now;)
If you want to recycle your error messages and have them look the same across your app I would recommend something like this (way I have learned with Michael Hartl tut):
Create partial for error messages:
layouts/_error_messages.html.erb
Put inside following code (here I use some bootstrap 3 classes):Now you have something recyclable and you can use it across the board. Instead of standard devise:
Call it in your form like this:
You can put it in any form. Instead of passing devise resource you can pass variable from your form like this:
Create DeviseHelper:
In your view, substitute
To:
Just to add to Eric Hu answer above where all the If statements are used, rather do something like this instead.