Module: I18nCountrySelect::InstanceTag
- Includes:
- Countries
- Defined in:
- lib/i18n_country_select/instance_tag.rb
Constant Summary
Constants included from Countries
Instance Method Summary collapse
-
#country_code_select(priority_countries, options, html_options) ⇒ Object
Adapted from Rails country_select.
- #country_translations ⇒ Object
- #to_country_code_select_tag(priority_countries, html_options = {}, options = {}) ⇒ Object
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.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/i18n_country_select/instance_tag.rb', line 14 def country_code_select(priority_countries, , ) selected = object.send(@method_name) if object.respond_to?(@method_name) countries = "" if .present? and [:include_blank] option = [:include_blank] == true ? "" : [:include_blank] countries += "<option>#{option}</option>\n" end if priority_countries countries += (priority_countries, selected) countries += "<option value=\"\" disabled=\"disabled\">-------------</option>\n" end countries = countries + (country_translations, selected) = .stringify_keys add_default_name_and_id() content_tag(:select, countries.html_safe, ) end |
#country_translations ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/i18n_country_select/instance_tag.rb', line 37 def country_translations Thread.current[:country_translations] ||= {} Thread.current[:country_translations][I18n.locale] ||= begin COUNTRY_CODES.map do |code| translation = I18n.t(code, :scope => :countries, :default => 'missing') translation == 'missing' ? nil : [translation, code] end.compact.sort_by do |translation, code| normalize_translation(translation) end end end |
#to_country_code_select_tag(priority_countries, html_options = {}, options = {}) ⇒ Object
5 6 7 8 9 10 11 |
# File 'lib/i18n_country_select/instance_tag.rb', line 5 def to_country_code_select_tag(priority_countries, = {}, = {}) # Rails 4 stores options sent when creating an InstanceTag. # Let's use them! = @options if defined?(@options) country_code_select(priority_countries, , ) end |