# Rails 3: Change validation error formatting?

**URL:** <https://www.ruby-forum.com/t/rails-3-change-validation-error-formatting/188443>\
**Category:** Rails\
**Created:** [May 12, 2010, 3:09am UTC](https://www.ruby-forum.com/t/rails-3-change-validation-error-formatting/188443 "2010-05-12T03:09:45Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mike](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/58f4c7/32.png) [@mike](https://www.ruby-forum.com/u/mike)\
**Post date:** [May 12, 2010, 3:09am UTC](https://www.ruby-forum.com/t/rails-3-change-validation-error-formatting/188443/1 "2010-05-12T03:09:45Z")

</div>

Hello, I’ve been reading that Rails 3 offers a bunch of new validation  
features.

Is there a way to customize the validation error formatting? For  
example, I prefer to style the elements surrounding a form input  
containing an error, not just the input itself.

Also, I might like to define my own class names for styling these  
elements, for example if they don’t conform to my naming standards.

Is this easier in Rails 3 than in 2?

I found a few articles about new validation functionality, but they  
seem to be formatting the old way.

Thanks.

---

<div class="post-metadata">

**Author:** ![mike](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/58f4c7/32.png) [@mike](https://www.ruby-forum.com/u/mike)\
**Post date:** [May 14, 2010, 5:21am UTC](https://www.ruby-forum.com/t/rails-3-change-validation-error-formatting/188443/2 "2010-05-14T05:21:36Z")

</div>

Since I have no experience Rails 2, I can’t compare the two. However,  
it’s pretty easy with Rails 3. You can override the default behavior  
like so:

ActionView::Base.field\_error\_proc = Proc.new do |html\_tag, instance|  
\*\*\* YOUR CODE HERE \*\*\*  
end

The README that comes with the ActionPack gem has a more verbose  
explanation about this. (I just wish there was a way to tell it to add  
some kind of styling if a field validated properly!)

---

<div class="post-metadata">

**Author:** ![mike](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/58f4c7/32.png) [@mike](https://www.ruby-forum.com/u/mike)\
**Post date:** [May 14, 2010, 3:16pm UTC](https://www.ruby-forum.com/t/rails-3-change-validation-error-formatting/188443/3 "2010-05-14T15:16:19Z")

</div>

Hello, thanks for your response.

I’m looking at actionpack-3.0.0.beta3/README and can’t find any  
mention of this.

Using the example below, is there a way to style the elements  
surrounding the invalid input (and not just the input itself)?

I’d like to change the CSS class name, too. Basically I’d like to  
customize validation without adding a ton of overhead to the  
framework’s existing procedures.
