devise_error_messages - How to move errors to the Rails flash ?

2,375 views
Skip to first unread message

lineonup

unread,
May 26, 2011, 2:05:15 PM5/26/11
to plataforma...@googlegroups.com
Hello, 

My default devise has all the error messages here: devise_error_messages

My understanding is devise_error_messages is temporary. What I want to do is make all the devise errors message show up in the rails standard:

<% flash.each do |key, value| %> .....


Is there a way to modify the devise_helper.rb to place the errors message in the flash?

Thanks

pedrobachiega

unread,
Jun 17, 2011, 2:24:20 PM6/17/11
to Devise
You could create a devise_helper.rb into your application and put this
code:

def devise_error_messages!
return "" if resource.errors.empty?
messages = resource.errors.full_messages.map { |msg|
flash.now[:error] = msg }.join
end

But this way you don't support I18n.
See the source-code for the helper here:
https://github.com/plataformatec/devise/blob/master/app/helpers/devise_helper.rb

Good luck!

pedrobachiega

unread,
Jun 17, 2011, 2:51:34 PM6/17/11
to Devise
Oops, I made a mistake :(

By this way, at your view, you still need call devise_error_messages!
and after flash...

Sorry.

On Jun 17, 3:24 pm, pedrobachiega <pedro.bachi...@gmail.com> wrote:
> You could create a devise_helper.rb into your application and put this
> code:
>
>   def devise_error_messages!
>     return "" if resource.errors.empty?
>     messages = resource.errors.full_messages.map { |msg|
> flash.now[:error] = msg }.join
>   end
>
> But this way you don't support I18n.
> See the source-code for the helper here:https://github.com/plataformatec/devise/blob/master/app/helpers/devis...
Reply all
Reply to author
Forward
0 new messages