Module: ActionView::Helpers::FormOptionsHelper

Defined in:
lib/localized_country_select.rb

Instance Method Summary collapse

Instance Method Details

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

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



76
77
78
79
80
81
82
83
# File 'lib/localized_country_select.rb', line 76

def country_options_for_select(selected = nil, priority_countries = nil, options = {})
  country_options = "".html_safe
  if priority_countries.present?
    country_options += options_for_select(LocalizedCountrySelect::priority_countries_array(priority_countries, options), selected)
    country_options += "<option value=\"\" disabled=\"disabled\">-------------</option>\n".html_safe
  end
  return country_options + options_for_select(LocalizedCountrySelect::localized_countries_array(options), 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 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



61
62
63
# File 'lib/localized_country_select.rb', line 61

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

#country_select_tag(name, selected_value = nil, priority_countries = nil, html_options = {}) ⇒ Object

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



69
70
71
# File 'lib/localized_country_select.rb', line 69

def country_select_tag(name, selected_value = nil, priority_countries = nil, html_options = {})
  select_tag(name.to_sym, country_options_for_select(selected_value, priority_countries), html_options.stringify_keys)
end