Module: ActionView::Helpers::FormOptionsHelper

Defined in:
lib/carmen/action_view_helpers.rb

Instance Method Summary collapse

Instance Method Details

#country_options_for_select(selected = nil, priority_country_codes = nil, options = {}) ⇒ Object

Returns a string of option tags for pretty much any country in the world. Supply a country name as selected to have it marked as the selected option tag. You can also supply a list of country codes as additional parameters, so that they will be listed above the rest of the (long) list.



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/carmen/action_view_helpers.rb', line 23

def country_options_for_select(selected = nil, priority_country_codes = nil, options = {})
  country_options = ""

  unless priority_country_codes.empty?
    priority_countries = Carmen.countries(options.dup).select do |pair| name, code = pair
      priority_country_codes.include?(code)
    end
    unless priority_countries.empty?
      priority_countries = priority_countries.sort_by { |name, code| priority_country_codes.index(code) }
      country_options += options_for_select(priority_countries, selected)
      country_options += "\n<option value=\"\" disabled=\"disabled\">-------------</option>\n"
    end
  end

  return country_options + options_for_select(Carmen.countries(options), priority_country_codes.include?(selected) ? nil : selected)
end

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

Return select and option tags for the given object and method, using country_options_for_select to generate the list of option tags.



10
11
12
# File 'lib/carmen/action_view_helpers.rb', line 10

def country_select(object, method, priority_countries = nil, options = {}, html_options = {})
  InstanceTag.new(object, method, self, options.delete(:object)).to_country_select_tag(priority_countries, options, html_options)
end

#state_options_for_select(selected = nil, country = Carmen.default_country) ⇒ Object

Returns a string of option tags containing the state names and codes for the specified country code, or nil if the states are not know for that country. Supply a state code as selected to have it marked as the selected option tag.



16
17
18
# File 'lib/carmen/action_view_helpers.rb', line 16

def state_options_for_select(selected = nil, country = Carmen.default_country)
  options_for_select(Carmen.states(country), selected)
end

#state_select(object, method, country = Carmen.default_country, options = {}, html_options = {}) ⇒ Object

Return select and option tags for the given object and method, using state_options_for_select to generate the list of option tags.



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

def state_select(object, method, country = Carmen.default_country, options={}, html_options={})
  InstanceTag.new(object, method, self, options.delete(:object)).to_state_select_tag(country, options, html_options)
end