Displaying rails form validation errors inline

HI i am using the following to display the from validation errors
inline in the views, as suggested in the rails guide.http://
guides.rubyonrails.org/active_record_validations_callbacks.html

ActionView::Base.field_error_proc = Proc.new do |html_tag, instance|
if instance.error_message.kind_of?(Array)
%(#{html_tag} 
#{instance.error_message.join(‘,’)}
).html_safe
else
%(#{html_tag} 
#{instance.error_message}
).html_safe
end
end

It’s working, but displaying the same error message twice, one before
the input field and one after the input field. Can’t figure out…

What does your view look like? Do you have any error message related
code
in there?

What does the output HTML look like? Is the error message repeated in
the
HTML?

say for instance,
i have a validation on
validates first_name, :presence => true

                                        ----------------------

First Name: can’t be blank | | can’t be
blank
----------------------

:slight_smile: so like above, the error message coming twice beside the input
field, if the validation fails.

I found that the validation error is coming for f.label as well.
Why is this happening? if i remove f.label and put not text without
using label tag, it is only coming once for text input.

Anybody there…

I know its an old post, but if anyone is facing this issue now, you can
check if the html_tag is not label, using something like:

html_tag !~ /label/

Also, I would recommend using simple_form which comes with inline error
messages.

venkata reddy wrote in post #1041460:

I found that the validation error is coming for f.label as well.
Why is this happening? if i remove f.label and put not text without
using label tag, it is only coming once for text input.

Anybody there…

I’m having the same exact issue as well so if anyone could help us out
that would be great! I spent the morning trouble shooting this issue and
had zero luck.