I am trying to add field errors in rails with field_error_proc
. But I could not find a way to add the error with the field name. Below is the code that I am using to generate a field with errors in rails.
ActionView::Base.field_error_proc = proc do |html_tag, instance|
if html_tag =~ /^<label/
%(#{html_tag}).html_safe
else
%(#{html_tag}<div class="help-block"><ul role="alert"><li>#{instance.error_message.first}</li></ul></div>).html_safe
end
end
below is the output of the above code. What I want is to have an error with field name like "Email is required" so as to have the common pattern for error(same as FE validation error)
This is the output of the FE validation.