Module: ActionView::Helpers::FormOptionsHelper

Defined in:
lib/localized_country_select.rb

Instance Method Summary collapse

Instance Method Details

#localized_country_options_for_select(selected = nil, priority_countries = nil, options = {}) ⇒ Object Also known as: country_options_for_select

Returns a string of option tags for countries according to locale. Supply the country code in upper-case (‘US’, ‘DE’) as selected to have it marked as the selected option tag. Country codes listed as an array of symbols in priority_countries argument will be listed first



84
85
86
87
88
89
90
91
92
93
# File 'lib/localized_country_select.rb', line 84

def localized_country_options_for_select(selected = nil, priority_countries = nil, options={})
  country_options = "".html_safe
  if priority_countries
    country_options += options_for_select(LocalizedCountrySelect::priority_countries_array(priority_countries, options), selected)
    country_options += "<option value=\"\" disabled=\"disabled\">-------------</option>\n".html_safe
    return country_options + options_for_select(LocalizedCountrySelect::localized_countries_array(options) - LocalizedCountrySelect::priority_countries_array(priority_countries, options), selected)
  else
    return country_options + options_for_select(LocalizedCountrySelect::localized_countries_array(options), selected)
  end
end

#localized_country_select(object, method, priority_countries = nil, options = {}, html_options = {}) ⇒ Object Also known as: country_select

Return select and option tags for the given object and method, using localized_country_options_for_select to generate the list of option tags. Uses country code, not name as option value. Country codes listed as an array of symbols in priority_countries argument will be listed first TODO : Implement pseudo-named args with a hash, not the “somebody said PHP?” multiple args sillines



59
60
61
62
63
64
65
66
67
68
69
# File 'lib/localized_country_select.rb', line 59

def localized_country_select(object, method, priority_countries = nil, options = {}, html_options = {})
  tag = if defined?(ActionView::Helpers::InstanceTag) &&
          ActionView::Helpers::InstanceTag.instance_method(:initialize).arity != 0

          InstanceTag.new(object, method, self, options.delete(:object))
        else
          CountrySelect.new(object, method, self, options)
        end

  tag.to_localized_country_select_tag(priority_countries, options, html_options)
end

#localized_country_select_tag(name, selected_value = nil, priority_countries = nil, html_options = {}) ⇒ Object Also known as: country_select_tag

Return “named” select and option tags according to given arguments. Use selected_value for setting initial value It behaves likes older object-binded brother localized_country_select otherwise TODO : Implement pseudo-named args with a hash, not the “somebody said PHP?” multiple args sillines



76
77
78
# File 'lib/localized_country_select.rb', line 76

def localized_country_select_tag(name, selected_value = nil, priority_countries = nil, html_options = {})
  select_tag name.to_sym, localized_country_options_for_select(selected_value, priority_countries).html_safe, html_options.stringify_keys
end