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)
- if object and object.errors and object.errors.include?(args[0])
- ps = method(:original_#{field}).parameters
- index = ps.index{|a| a[1] == :options }
- args[index] ||= {}
- args[index][:class] ||= ""
- args[index][:class] += " #{CSS_ERROR_CLASS}"
- end
- super(*args, &block)
- end
- }
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement