Module: ActionView::Helpers::FormOptionsHelper

Defined in:
lib/list_select.rb,
lib/list_select.rb

Instance Method Summary collapse

Instance Method Details

#country_select(object, method, priority_countries = nil, options = {}, html_options = {}) ⇒ Object



53
54
55
56
57
# File 'lib/list_select.rb', line 53

def country_select(object, method, priority_countries = nil, options = {}, html_options = {})
  options = options.merge(:priority_items => priority_countries) if priority_countries
  list = options.delete(:list) || :countries_cldr
  list_select(object, method, list, options, html_options)
end

#list_options_for_select(list, selected = nil, priority_items = nil) ⇒ Object



15
16
17
18
19
20
21
22
23
# File 'lib/list_select.rb', line 15

def list_options_for_select(list, selected = nil, priority_items = nil)
  list_options = ""
  items = I18n.translate(list)
  unless priority_items.blank?
    list_options += options_for_select(priority_items.map{|key| [items[key], key.to_s]}, selected)
    list_options += "<option value=\"\" disabled=\"disabled\">-------------</option>\n"
  end
  return list_options + options_for_select(items.map{|k, v| [v, k.to_s]}.sort, selected)
end

#list_select(object, method, list, options = {}, html_options = {}) ⇒ Object



5
6
7
# File 'lib/list_select.rb', line 5

def list_select(object, method, list, options = {}, html_options = {})
  InstanceTag.new(object, method, self,  options.delete(:object)).to_list_select_tag(list, options, html_options)
end

#list_select_tag(name, list, options = {}, html_options = {}) ⇒ Object



9
10
11
12
13
# File 'lib/list_select.rb', line 9

def list_select_tag(name, list, options={}, html_options = {})
   :select,
              list_options_for_select(list, options[:default], options[:priority_items]),
              { "name" => name, "id" => name }.update(html_options.stringify_keys)
end