Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class FormBuilder < ActionView::Helpers::FormBuilder
- CSS_ERROR_CLASS = 'c1'
- ERRORABLE_FIELDS = [:label, :text_field, :text_area, :check_box, :radio_button]
- ERRORABLE_FIELDS.each do |field|
- class_eval %Q{
- alias :original_#{field} #{field}
- def #{field} (*args, &block)
- options = args.extract_options!
- if object and object.errors and object.errors.include?(args[0])
- options[:class] ||= ""
- options[:class] += " #{CSS_ERROR_CLASS}"
- end
- super *(args << options), &block
- end
- }
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement