Module: FriendsLabeledFormBuilder
- Defined in:
- app/helpers/friends_labeled_form_helper.rb
Instance Method Summary collapse
- #label_tag_for(method, options = {}) ⇒ Object
- #labeled_check_box(method, options = {}, checked_value = 1, unchecked_value = 0) ⇒ Object
- #labeled_radio_button(method, value, options = {}) ⇒ Object
- #labeled_text_field(method, options = {}) ⇒ Object
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, = {}) [:label] ||= object.class.try(:human_attribute_name, method) @template.label_tag_for(@object_name, method, ) 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, = {}, checked_value=1, unchecked_value=0) [:class] ||= "" [:label] ||= object.class.try(:human_attribute_name, method) [:class] << " error" if ((!object.errors[method.to_sym].empty? && !object.new_record?) rescue false ) [:errors] = ((object.errors[method.to_sym].empty? ? nil : object.errors[method.to_sym]) rescue false ) [:checked] ||= ((object.send(method) rescue false) || [:checked]) @template.labeled_check_box(@object_name, method, , 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 (method, value, ={}) [:checked] = (object.send(method) == value) if [:checked].nil? # try auto-setting label [:label] ||= object.class.try(:human_attribute_name, method) [:class] ||= "" [:class] << " error" if ((!object.errors[method.to_sym].empty? && !object.new_record?) rescue false ) [:errors] = ((object.errors[method.to_sym].empty? ? nil : object.errors[method.to_sym]) rescue false ) @template.(@object_name, method, value, ) 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, = {}) [:value] ||= (object.send(method) rescue nil ) [:label] ||= object.class.try(:human_attribute_name, method) [:class] ||= "" [:class] << " error" if ((!object.errors[method.to_sym].empty? && !object.new_record?) rescue false ) [:errors] = ((object.errors[method.to_sym].empty? ? nil : object.errors[method.to_sym]) rescue false ) @template.labeled_text_field(@object_name, method, ) end |