The standard Rails validation wraps my error-filled fields in a div of class fieldWithErrors.
How can I change it so that the erroneous element’s parent gets assigned that class instead of having a new div created on the page?
EDIT:
Per this website, this wraps errors in spans instead of divs, which helps my formatting a little, but I’d really love to just stick the error class in the parent element…
app/config/environment.rb (in the initializer block):
config.action_view.field_error_proc = Proc.new { |html_tag, instance| %(<span class="fieldWithErrors">#{html_tag}</span>) }
The Hpricot method listed on that site looks like what I want, but I don’t know where I should be putting it. I also keep getting uninitialized constant ActionView errors too. Can someone help?
Awesome!
I figured out how to get this post working (I know, I’m such a newbie).
Create a new file in
app/config/initializers; I called mineerror_formatting.rb.Paste the optimized method from the website listed above in there:
Save. Throw in some hpricot with a pinch of
config.gem 'hpricot'in theapp/config/environment.rbintializer block, thenrake gems:install, restart the app, and now my app is working exactly the way I want it too, like a cute little kitten.