Module: FriendsLabeledFormBuilder

Defined in:
app/helpers/friends_labeled_form_helper.rb

Instance Method Summary collapse

Instance Method Details

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



94
95
96
97
# File 'app/helpers/friends_labeled_form_helper.rb', line 94

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



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

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



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

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



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

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