# Can error\_message\_on display multiple errors?

**URL:** <https://www.ruby-forum.com/t/can-error-message-on-display-multiple-errors/157426>\
**Category:** Rails\
**Created:** [January 11, 2009, 5:46am UTC](https://www.ruby-forum.com/t/can-error-message-on-display-multiple-errors/157426 "2009-01-11T05:46:39Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![scottnj](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b9e5f3/32.png) [@scottnj](https://www.ruby-forum.com/u/scottnj)\
**Post date:** [January 11, 2009, 5:46am UTC](https://www.ruby-forum.com/t/can-error-message-on-display-multiple-errors/157426/1 "2009-01-11T05:46:39Z")

</div>

Is there an easy way to make error\_message\_on display more than just  
one error message? I know I could create a custom form builder, but it  
looks complicated and I would rather learn that when I have more time.

---

<div class="post-metadata">

**Author:** ![scottnj](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b9e5f3/32.png) [@scottnj](https://www.ruby-forum.com/u/scottnj)\
**Post date:** [January 12, 2009, 12:19am UTC](https://www.ruby-forum.com/t/can-error-message-on-display-multiple-errors/157426/2 "2009-01-12T00:19:58Z")

</div>

for anyone else who might come across this, i found field\_error\_proc.  
you can over ride it and have it automatically add the errors, you can  
leave the error\_message\_on out of your code completely. you just add  
this code to an initializer.

i combined it with the second example to also stop rails from putting  
those annoying divs around the fields with errors, it makes much more  
sense to simply add a css class to the fields.

[http://snippets.dzone.com/posts/show/1671](http://snippets.dzone.com/posts/show/1671)

ActionView::Base.field\_error\_proc = Proc.new {|html\_tag, instance|  
if instance.error\_message.kind\_of?(Array)  
%(#{html\_tag}←#  
{instance.error\_message.join(‘,’)})  
else  
%(#{html\_tag}←#  
{instance.error\_message})  
end  
}

[http://thewebfellas.com/blog/2008/4/21/error-fields-with-a-hpricot-twist](http://thewebfellas.com/blog/2008/4/21/error-fields-with-a-hpricot-twist)

ActionView::Base.field\_error\_proc = Proc.new do |html\_tag, instance|  
if html\_tag =~ /\<(input|label|textarea|select)/  
error\_class = ‘error’  
nodes = Hpricot(html\_tag)  
nodes.each\_child { |node| node[:class] = node.classes.push  
(error\_class).join(’ ') unless !node.elem? || node[:type] == ‘hidden’  
|| node.classes.include?(error\_class) }  
nodes.to\_html  
else  
html\_tag  
end  
end
