The much maligned but otherwise innocent "devise_error_messages!" method
in the DeviseHelper module starts out with:
return "" if resource.errors.empty?
My question: where is 'resource' set up? I'd like to replicate its
functionality, but my naive approach (creating a FooHelper module in
app/helpers) fails because 'resource' isn't bound.
Another way to ask the question: rather than creating specific error
handlers for User, Topic, Profile, etc, I'd like to write a single error
handling helper that can be used for any model.
Right now each of my _form.html.erb files start with something like:
<% if @user.errors.any? %>
<h2><%= pluralize(@user.errors.count, "error") %> prohibited this user
from being saved:</h2>
<% @user.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
<% end %>
... but it's clearly unDRY to replicate that for @user, @topic,
@profile. How can I write a helper that will generalize to the current
P.S.: Anyone looking to eliminate the "DEPRECATION WARNING:
f.error_messages was removed from Rails" warning might be interested in
the answer to this thread. Now it will turn up in a search...