## Overriding ActionView::Base.field_error_proc in Rails ActionView::Base.field_error_proc = Proc.new do |html_tag, instance| html = %(
#{html_tag}
).html_safe # add nokogiri gem to Gemfile form_fields = [ 'textarea', 'input', 'select' ] elements = Nokogiri::HTML::DocumentFragment.parse(html_tag).css "label, " + form_fields.join(', ') elements.each do |e| if e.node_name.eql? 'label' html = %(
#{e}
).html_safe elsif form_fields.include? e.node_name if instance.error_message.kind_of?(Array) html = %(
#{html_tag} #{instance.error_message.uniq.join(', ')}
).html_safe unless html_tag =~ /hidden/ else html = %(
#{html_tag} #{instance.error_message}
).html_safe unless html_tag =~ /hidden/ end end end html end