Module: FriendsLabeledFormBuilder

Defined in:
app/helpers/friends_labeled_form_helper.rb

Instance Method Summary collapse

Instance Method Details

#label_tag_for(method, options = {}) ⇒ Object



92
93
94
95
# File 'app/helpers/friends_labeled_form_helper.rb', line 92

def label_tag_for(method, options = {})
  options[:label] ||= object.class.try(:human_attribute_name, method)
  @template.label_tag_for(@object_name, method, options)
end

#labeled_check_box(method, options = {}, checked_value = 1, unchecked_value = 0) ⇒ Object



112
113
114
115
116
117
118
119
120
121
122
# File 'app/helpers/friends_labeled_form_helper.rb', line 112

def labeled_check_box(method, options = {}, checked_value=1, unchecked_value=0)

  options[:class] ||= ""
  options[:label] ||= object.class.try(:human_attribute_name, method)

  options[:class] << " error" if ((!object.errors[method.to_sym].empty? && !object.new_record?) rescue false  )
  options[:errors] = ((object.errors[method.to_sym].empty? ? nil : object.errors[method.to_sym]) rescue false )

  options[:checked] ||= ((object.send(method) rescue false) || options[:checked])
  @template.labeled_check_box(@object_name, method, options, checked_value, unchecked_value)
end

#labeled_radio_button(method, value, options = {}) ⇒ Object



98
99
100
101
102
103
104
105
106
107
108
109
# File 'app/helpers/friends_labeled_form_helper.rb', line 98

def labeled_radio_button(method, value, options ={})
  options[:checked] = (object.send(method) == value) if options[:checked].nil?

  # try auto-setting label
  options[:label] ||= object.class.try(:human_attribute_name, method)

  options[:class] ||= ""
  options[:class] << " error" if ((!object.errors[method.to_sym].empty? && !object.new_record?) rescue false  )
  options[:errors] = ((object.errors[method.to_sym].empty? ? nil : object.errors[method.to_sym]) rescue false )

  @template.labeled_radio_button(@object_name, method, value, options)
end

#labeled_text_field(method, options = {}) ⇒ Object



125
126
127
128
129
130
131
132
133
134
135
136
# File 'app/helpers/friends_labeled_form_helper.rb', line 125

def labeled_text_field(method, options = {})

  options[:value] ||= (object.send(method) rescue nil )
  options[:label] ||= object.class.try(:human_attribute_name, method)

  options[:class] ||= ""
  options[:class] << " error" if ((!object.errors[method.to_sym].empty? && !object.new_record?) rescue false )

  options[:errors] = ((object.errors[method.to_sym].empty? ? nil : object.errors[method.to_sym]) rescue false )

  @template.labeled_text_field(@object_name, method, options)
end