Module: I18nCountrySelect::InstanceTag

Includes:
Countries
Defined in:
lib/i18n_country_select/instance_tag.rb

Constant Summary

Constants included from Countries

Countries::COUNTRY_CODES

Instance Method Summary collapse

Instance Method Details

#country_code_select(priority_countries, options, html_options) ⇒ Object

Adapted from Rails country_select. Just uses country codes instead of full names.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/i18n_country_select/instance_tag.rb', line 10

def country_code_select(priority_countries, options, html_options)
	selected = object.send(@method_name)
    
    country_translations = COUNTRY_CODES.map{|code| [I18n.t(code, :scope => :countries), code]}

	countries = ""
	if priority_countries
		countries += options_for_select(priority_countries, selected)
		countries += "<option value=\"\" disabled=\"disabled\">-------------</option>\n"
    elsif options[:include_blank]
      countries += "<option value=\"\">" + options[:include_blank] + "</options>\n"
		countries += "<option value=\"\" disabled=\"disabled\">-------------</option>\n"
	end

	countries = countries + options_for_select(country_translations, selected)
	
    html_options = html_options.stringify_keys
    add_default_name_and_id(html_options)

    (:select, countries.html_safe, html_options)
end

#to_country_code_select_tag(priority_countries, options = {}, html_options = {}) ⇒ Object



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

def to_country_code_select_tag(priority_countries, options = {}, html_options = {})
	country_code_select(priority_countries, options, html_options)
end