Module: Homeschool::FormBuildr::InstanceMethods
- Defined in:
- lib/form_buildr.rb
Instance Method Summary collapse
- #label_for(method, options = {}) ⇒ Object
- #labeled_check_box(method, options = {}, checked_value = "1", unchecked_value = "0") ⇒ Object
- #labeled_collection_select(method, collection, value_method, text_method, options = {}, html_options = {}) ⇒ Object
- #labeled_radio_button(method, tag_value, options = {}) ⇒ Object
- #labeled_select(method, choices, options = {}, html_options = {}) ⇒ Object
Instance Method Details
#label_for(method, options = {}) ⇒ Object
41 42 43 44 45 46 47 48 49 |
# File 'lib/form_buildr.rb', line 41 def label_for(method, ={}) = {:label => } if .is_a? String begin label = [:label] || @object_name.to_s.classify.constantize.human_name(method) rescue NameError label = method.to_s.titleize end %{<label class="fieldLabel" for="#{[:id] || "#{@object_name}_#{method}"}">#{label}#{":" if ![:no_colon]}</label>} end |
#labeled_check_box(method, options = {}, checked_value = "1", unchecked_value = "0") ⇒ Object
56 57 58 |
# File 'lib/form_buildr.rb', line 56 def labeled_check_box(method, ={}, checked_value="1", unchecked_value="0") send(:check_box, method, .without(:label, :no_colon), checked_value, unchecked_value) + send(:label_for, method, .update(:no_colon => true)) end |
#labeled_collection_select(method, collection, value_method, text_method, options = {}, html_options = {}) ⇒ Object
64 65 66 |
# File 'lib/form_buildr.rb', line 64 def labeled_collection_select(method, collection, value_method, text_method, ={}, ={}) label_for(method, ) + collection_select(method, collection, value_method, text_method, .without(:label, :no_colon), ) end |
#labeled_radio_button(method, tag_value, options = {}) ⇒ Object
51 52 53 54 |
# File 'lib/form_buildr.rb', line 51 def (method, tag_value, ={}) id = %{#{@object_name}_#{method}_#{tag_value}} send(:radio_button, method, tag_value, {:id => id}.update(.without(:label, :no_colon))) + send(:label_for, method, {:no_colon => true, :label => tag_value.to_s.humanize, :id => id}.update()) end |
#labeled_select(method, choices, options = {}, html_options = {}) ⇒ Object
60 61 62 |
# File 'lib/form_buildr.rb', line 60 def labeled_select(method, choices, ={}, ={}) label_for(method, ) + select(method, choices, .without(:label, :no_colon), ) end |