Module: Padrino::Helpers::FormHelpers
- Defined in:
- lib/padrino-fields/form_helpers.rb
Instance Method Summary collapse
- #blank_option(prompt) ⇒ Object
- #grouped_options_for_select(collection, selected = nil, prompt = false) ⇒ Object
- #select_tag(name, options = {}) ⇒ Object
Instance Method Details
#blank_option(prompt) ⇒ Object
51 52 53 54 55 56 57 58 59 |
# File 'lib/padrino-fields/form_helpers.rb', line 51 def blank_option(prompt) if prompt case prompt.class.to_s when 'String' ; content_tag(:option, prompt, :value => '') ; when 'Array' ; content_tag(:option, prompt.first, :value => prompt.last) ; else ; content_tag(:option, '', :value => '') ; end end end |
#grouped_options_for_select(collection, selected = nil, prompt = false) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/padrino-fields/form_helpers.rb', line 35 def (collection,selected=nil,prompt=false) if collection.is_a?(Hash) collection.map do |key, value| content_tag :optgroup, :label => key do (value, selected) end end elsif collection.is_a?(Array) collection.map do |optgroup| content_tag :optgroup, :label => optgroup.first do (optgroup.last, selected) end end end end |
#select_tag(name, options = {}) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/padrino-fields/form_helpers.rb', line 21 def select_tag(name, ={}) .reverse_merge!(:name => name) collection, fields = .delete(:collection), .delete(:fields) [:options] = (collection, fields) if collection prompt = .delete(:include_blank) = if [:options] (.delete(:options), .delete(:selected)) elsif [:grouped_options] (.delete(:grouped_options), .delete(:selected), prompt) end.unshift(blank_option(prompt)) .merge!(:name => "#{[:name]}[]") if [:multiple] content_tag(:select, , ) end |