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
100 101 102 103 |
# File 'app/helpers/friends_labeled_form_helper.rb', line 100 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
120 121 122 123 124 125 126 127 128 129 130 |
# File 'app/helpers/friends_labeled_form_helper.rb', line 120 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
106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'app/helpers/friends_labeled_form_helper.rb', line 106 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
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'app/helpers/friends_labeled_form_helper.rb', line 133 def labeled_text_field(method, = {}) [:class] ||= "" [:class] << " error" if ((!object.errors[method.to_sym].empty? && !object.new_record?) rescue false ) # getting euro value if possible if method.to_s.match(/euro|percent/) [:value] ||= (object.send(method) rescue nil).try(:to_euro) [:class] << " euro-percent-value" else [:value] ||= (object.send(method) rescue nil ) end [:label] ||= object.class.try(:human_attribute_name, method) [:errors] = ((object.errors[method.to_sym].empty? ? nil : object.errors[method.to_sym]) rescue false ) @template.labeled_text_field(@object_name, method, ) end |