Forum: Ruby on Rails can error_message_on display multiple errors?

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Scott N. (Guest)
on 2009-01-11 06:46
(Received via mailing list)
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.
Scott N. (Guest)
on 2009-01-12 01:19
(Received via mailing list)
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.

ActionView::Base.field_error_proc = {|html_tag, instance|
  if instance.error_message.kind_of?(Array)
    %(#{html_tag}<span class='validation-error'>&larr;#
    %(#{html_tag}<span class='validation-error'>&larr;#

ActionView::Base.field_error_proc = 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) }
This topic is locked and can not be replied to.