Work around for problems with error_message_on

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