lib/formal.rb in formal-0.0.2 vs lib/formal.rb in formal-0.0.3

- old
+ new

@@ -3,11 +3,11 @@ module Formal class Builder < ActionView::Helpers::FormBuilder ActionView::Base.field_error_proc = proc { |input, instance| input } - @@field_helper_methods = %w(label_tag text_field password_field text_area select email_field search_field) + @@field_helper_methods = %w(label_tag text_field password_field text_area select email_field search_field telephone_field number_field file_field range_field) def label(method, text = nil, options = {}, &block) text = text || method.to_s.humanize if object.errors.any? @@ -21,11 +21,12 @@ end end @@field_helper_methods.each do |method_name| define_method method_name do |*args| - if object.errors.any? + method_name = args.first + if object.errors[method_name].present? @template.content_tag(:dd, super(*args), class: 'error') else @template.content_tag(:dd, super(*args)) end end @@ -34,8 +35,8 @@ def check_box_with_label(method, text = nil, *args) text = text || method.to_s box = [check_box(method, *args).html_safe, text].join(" ") label(method, box, *args) end - end + end