method
error_message_on
![Wide documentation Importance_3](https://d2vfyqvduarcvs.cloudfront.net/images/importance_3.png?1349367920)
error_message_on(object, method, prepend_text = "", append_text = "", css_class = "formError")
public
Returns a string containing the error message attached to the method on the object, if one exists. This error message is wrapped in a DIV tag, which can be specialized to include both a prepend_text and append_text to properly introduce the error and a css_class to style it accordingly. Examples (post has an error message "can’t be empty" on the title attribute):
<%= error_message_on "post", "title" %> => <div class="formError">can't be empty</div> <%= error_message_on "post", "title", "Title simply ", " (or it won't work)", "inputError" %> => <div class="inputError">Title simply can't be empty (or it won't work)</div>
Register or
log in
to add new notes.
hosiawak -
August 12, 2008
![Default_avatar_30](https://www.gravatar.com/avatar/8cb2fab8fddc8626073f40f0106c0077?default=http://apidock.com/images/default_avatar_30.png&size=30)
9 thanks
Overriding the default div class="fieldWithErrors"
By default fields that are invalid are wrapped in:
<div class="fieldWithErrors"> <input type="text" name="blah"> </div>
To override and wrap in spans instead of divs place the following in your environment.rb:
ActionView::Base.field_error_proc = Proc.new { |html_tag, instance| "<span class=\"fieldWithErrors\">#{html_tag}</span>" }
or to not use wrapping at all:
ActionView::Base.field_error_proc = Proc.new { |html_tag, instance| "#{html_tag}" }