Hey all
I was encountering problems with error_message_on in the fact that it
caused an exception when no object by that name had any errors (or did
not exsist) so i created this work around...
def display_error(obj, method, prepend_text = "", append_text =
"",
css_class = "form_error")
object = instance_variable_get("@#{obj}")
if object && !object.errors.empty?
errors = object.errors.on(method)
if errors
content_tag("div", "#{prepend_text}#{errors.is_a?(Array)
?
errors.first : errors}#{append_text}", :class => css_class)
end
else
return nil
end
end
It just checks to see if there are any errors before trying to present
them
Hope this might one day help somone else!
Tim
--
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
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk
-~----------~----~----~----~------~----~------~--~---