Custom HTML error wrappers for form elements
I would like to find a way to configure html default error
<div class="field_with_errors"></div>
To take my own classes:
<div class="clearfix error">
<label for="errorInput">Input with error</label>
<div class="input">
<input class="xlarge error" id="errorInput" name="errorInput" size="30" type="text">
<span class="help-inline">Small snippet of help text</span>
</div>
</div>
I have found this railscast since 2007, which I believe uses Rails 2. http://railscasts.com/episodes/39-customize-field-error . It seems that Rails 3 might have a more convenient way to customize this html?
Furthermore, it does not show a way to simply add an error class directly to the input as I want.
The method described in the link you posted is still used today with vanilla form developers in Rails .
, , , , ActionView::Base.field_error_proc environment.rb, :
ActionView::Base.field_error_proc = Proc.new do |html_tag, instance|
if instance.error_message.kind_of?(Array)
%(<div class="form-field error">#{html_tag}<small class="error">
#{instance.error_message.join(',')}</small></div).html_safe
else
%(<div class="form-field error">#{html_tag}<small class="error">
#{instance.error_message}</small></div).html_safe
end
end
(# {html_tag}) <div class="form-field error>..</div>, ZURB Foundation. <small class="error">...</small ( ) .
, , simple_form. .
!