module CountrySelectEngine
CountrySelectEngine
¶ ↑
View helper for displaying select list with countries:
localized_country_select(:user, :country)
Works just like the default Rails’ country_select
plugin, but stores countries as country codes, not names, in the database.
You can easily translate country codes in your application like this:
<%= I18n.t @user.country, :scope => 'countries' %>
Uses the Rails internationalization framework (I18n) for translating the names of countries.
Use Rake task rake import:country_select 'de'
for importing country names from Unicode.org’s CLDR repository (www.unicode.org/cldr/data/charts/summary/root.html)
Code adapted from Rails’ default country_select
plugin (previously in core) See github.com/rails/country_select/tree/master/lib/country_select.rb
Constants
- VERSION
Public Class Methods
include_key?(key, options)
click to toggle source
# File lib/country-select-engine.rb, line 71 def self.include_key?(key, options) if options[:only] return options[:only].include?(key) end if options[:except] return !options[:except].include?(key) end true end
value_with_symbol(key, value, options = {})
click to toggle source
# File lib/country-select-engine.rb, line 49 def self.value_with_symbol(key, value, options = {}) if options[:timezone] timezone = ActiveSupport::TimeZone[key.to_s] if timezone offset = "GMT#{ActiveSupport::TimeZone[key.to_s].formatted_offset}" if options[:timezone] == :prepend return "(#{offset}) #{value}" elsif options[:timezone] == :append return "#{value} (#{offset})" end else return value end elsif options[:symbol] == :prepend return "#{key.to_s}, #{value}" elsif options[:symbol] == :append return "#{value} (#{key.to_s})" else return value end end