I figured out the answer to my own question, and I'm embarrassed by how
trivial it is: create a helper function that takes @user, @topic,
@profile etc as an argument. For example:
# app/helpers/my_helper.rb
module MyHelper
def my_error_message(obj)
return unless obj.errors.any?
summary = "#{pluralize(obj.errors.count, "error")} prevented this
#{obj.class} from being saved:"
msgs = obj.errors.full_messages.map { |msg| content_tag(:li, msg)
}.join
"<div
id=\"error_explanation\"><h3>#{summary}</h3><ul>#{msgs}</ul></div>".html_safe
end
end
Now you can sprinkle <%= my_error_message(@user) %> in the top of
user/_form.html.erb, etc. Works like a champ.
- ff
--
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.