The much maligned but otherwise innocent "devise_error_messages!" method
in the DeviseHelper module starts out with:
def devise_error_messages!
return "" if resource.errors.empty?
...
end
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? %>
<div id="error_explanation">
<h2><%= pluralize(@user.errors.count, "error") %> prohibited this user
from being saved:</h2>
<ul>
<% @user.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% 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
resource?
- ff
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...
--
Posted via http://www.ruby-forum.com/.
--
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.