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) ⇒ 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.



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

def country_options_for_select(selected = nil, *priority_country_codes)
  country_options = ""

  unless priority_country_codes.empty?
    priority_countries = Carmen.countries.select do |pair| name, code = pair
      priority_country_codes.include?(code)
    end
    unless priority_countries.empty?
      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, 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.



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

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.



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

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.



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

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