Module: CountryCodeSelect::InstanceTag

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

Constant Summary

Constants included from Countries

Countries::COUNTRIES

Instance Method Summary collapse

Instance Method Details

#country_code_select(priority_countries, 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
# File 'lib/country_code_select/instance_tag.rb', line 10

def country_code_select(priority_countries, options)
	selected = object.send(@method_name)

	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(COUNTRIES, selected)
    (:select, countries, options.merge(id: "#{@object_name}_#{@method_name}", :name => "#{@object_name}[#{@method_name}]"), false)
end

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



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

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