gregm
December 14, 2010, 9:05pm
1
Hi,
What do I have to override in order to be able to have the error message
of each field in front of the input field?
I haven’t been able to find anything similar on google. All I’ve found
is how to override the container around the input field.
ActionView::Base.field_error_proc = Proc.new { |html_tag, instance|
“<span class=“fieldWithErrors”>#{html_tag}” }
Or in here do we have access of the error message of the current field?
Greg
gregm
December 14, 2010, 9:27pm
2
No need to overwrite anything. You can simply access the
@resource.errors
hash and display the error if there is one…
<%= f.label(:author) %>
<% if @comment.errors [:author] %>
<%= @comment.errors [:author] =>
<% end %>
<% f.text_field(:author, :size=>20, :maxlength=>250) %>
gregm
December 14, 2010, 9:41pm
3
Tim S. wrote in post #968409:
No need to overwrite anything. You can simply access the
@resource.errors
hash and display the error if there is one…
<%= f.label(:author) %>
<% if @comment.errors [:author] %>
<%= @comment.errors [:author] =>
<% end %>
<% f.text_field(:author, :size=>20, :maxlength=>250) %>
Cool! Thanks!
gregm
February 7, 2011, 6:23pm
4
I have a problem with my bogus fields no longer highlighted by
fieldWithErrors.
In the railscasts video it works, but not on my app that I am currently
upgrading from 2.x to 3.0. In railscasts Ryan doesn’t have to test
manually if the field has an error.
Anyone run into this issue?
gregm
February 7, 2011, 6:29pm
5
My bad I just realized that they switched from camelCase css naming to
underscores.
I think Rails 3 introduced too many insignificant changes that are a
pain in the butt to track.