-
-
Save ckdake/769663 to your computer and use it in GitHub Desktop.
module DeviseHelper | |
def devise_error_messages! | |
unless resource.errors.empty? | |
content_tag :div, :id => "error_explanation", :escape => false do | |
content_tag(:h2, "The following errors were encountered:") + | |
content_tag(:ul, resource.errors.full_messages.map { |msg| content_tag(:li, msg) }.join.html_safe) | |
end.html_safe | |
end | |
end | |
end |
Ah, gotcha. I think it makes sense on a method that throws an error/drastically affects the flow (authenticate_user!), but not sure what is so "dangerous" about returning error messages :) I see now that it's what Devise is expecting, though.
Does the :escape key do anything there? In the docs, escape is a third argument, not an option passed in the options hash. Could be missing something though?
I was battling with things to get full html_safe content as just nesting like content_tag(:div, [content_tag(:h1, "h1"), content_tag(:h1,"h1 again")]).html_safe ends up with escaped html brackets on the h1s. Probably not needed!
Looks like you could probably do something like content_tag(:div, [...], {:id => '...'}, false) .. false being escape = false .. but that's pretty uglified? Maybe Ruby will have named arguments someday :)
Well, actually, named arguments may not help here unless you still used the block syntax or just wanted more clarity.
devise likes using bangs, i.e. 'before_filter :authenticate_user!".
This gist is for overriding their built in error message printing so that it's more consistent with the rest of an application I'm working on, so the name is stuck at the one they picked.