Advertisement
Guest User

Untitled

a guest
Jun 17th, 2012
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rails 0.60 KB | None | 0 0
  1.   class FormBuilder < ActionView::Helpers::FormBuilder
  2.     CSS_ERROR_CLASS = 'c1'
  3.     ERRORABLE_FIELDS = [:label, :text_field, :text_area, :check_box, :radio_button]
  4.  
  5.     ERRORABLE_FIELDS.each do |field|
  6.      class_eval %Q{
  7.         alias :original_#{field} #{field}
  8.         def #{field} (*args, &block)
  9.           options = args.extract_options!
  10.           if object and object.errors and object.errors.include?(args[0])
  11.             options[:class] ||= ""
  12.             options[:class] += " #{CSS_ERROR_CLASS}"
  13.           end
  14.           super *(args << options), &block
  15.         end
  16.       }
  17.     end
  18.   end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement