It needs a little tweak to make this work on rails 3, since it now 
protects all strings against XSS attacks(i.e. html escapes them).

The following works:
ActionView::Base.field_error_proc = Proc.new do |html_tag, instance|
  '<span class="field_with_errors">'.html_safe << html_tag << 
'</span>'.html_safe
end

Obs.: dunno if there isn't a better way of doing this on rails 3.

Marcel Molina Jr. wrote:
> On Sat, Mar 25, 2006 at 01:22:05PM +1100, Dan Harper wrote:
>> Does anyone know how to override the <div class="fieldWithErrors"> 
>> behaviour when a form field is incorrect?
> 
> This is what ActionView does:
> 
> module ActionView
>   class Base
>     @@field_error_proc = Proc.new{ |html_tag, instance| "<div 
> class=\"fieldWithErrors\">#{html_tag}</div>" }
>     cattr_accessor :field_error_proc
>   end
> end
> 
> You can set your own Proc. For example, in your config/environment.rb:
> 
> ActionView::Base.field_error_proc = Proc.new {|html_tag, instance| 
> %(<span class="field-with-errors">#{html_tag}</span>)}
> 
> marcel

-- 
Posted via http://www.ruby-forum.com/.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to