Module: CountryStateSelect
- Defined in:
- lib/country_state_select/engine.rb,
lib/country_state_select.rb,
lib/country_state_select/engine3.rb,
lib/country_state_select/railtie.rb,
lib/country_state_select/version.rb,
app/controllers/country_state_select/cscs_controller.rb
Overview
Defined Under Namespace
Modules: Rails Classes: CscsController
Constant Summary collapse
- VERSION =
"3.0.1"
Class Method Summary collapse
-
.cities_collection(f, options) ⇒ Object
Return either the City (String) or Cities (Array).
- .city_options(options) ⇒ Object
-
.collect_cities(state_id = '', country_id = '') ⇒ Object
Return the cities of given state and country.
-
.collect_states(country) ⇒ Object
Return the collected States for a given Country.
-
.countries_collection ⇒ Object
Collect the Countries.
-
.countries_except(*except) ⇒ Object
Pass array of unwanted countries to get back all except those in the array.
-
.state_options(options) ⇒ Object
Return a hash for use in the simple_form.
-
.states_collection(f, options) ⇒ Object
Return either the State (String) or States (Array).
Class Method Details
.cities_collection(f, options) ⇒ Object
Return either the City (String) or Cities (Array)
29 30 31 32 |
# File 'lib/country_state_select.rb', line 29 def self.cities_collection(f, ) cities = collect_cities(f.object.send([:state])) cities end |
.city_options(options) ⇒ Object
57 58 59 60 61 62 |
# File 'lib/country_state_select.rb', line 57 def self.() cities = cities_collection([:form], [:field_names]) = .merge(collection: cities) = .merge(:as => :string) if cities.class == String end |
.collect_cities(state_id = '', country_id = '') ⇒ Object
Return the cities of given state and country
41 42 43 44 45 46 47 |
# File 'lib/country_state_select.rb', line 41 def self.collect_cities(state_id = '', country_id = '') if state_id.nil? || country_id.nil? [] else CS.cities(state_id.to_sym, country_id.to_sym) end end |
.collect_states(country) ⇒ Object
Return the collected States for a given Country
36 37 38 |
# File 'lib/country_state_select.rb', line 36 def self.collect_states(country) CS.states(country).collect {|p| [ p[1], p[0] ] }.compact end |
.countries_collection ⇒ Object
Collect the Countries
12 13 14 |
# File 'lib/country_state_select.rb', line 12 def self.countries_collection CS.countries.except!(:COUNTRY_ISO_CODE).collect {|p| [ p[ 1], p[0] ] }.compact end |
.countries_except(*except) ⇒ Object
Pass array of unwanted countries to get back all except those in the array
17 18 19 |
# File 'lib/country_state_select.rb', line 17 def self.countries_except(*except) countries_collection.collect { |c| c unless except.include?(c.second) }.compact end |
.state_options(options) ⇒ Object
Return a hash for use in the simple_form
50 51 52 53 54 55 |
# File 'lib/country_state_select.rb', line 50 def self.() states = states_collection([:form], [:field_names]) = .merge(collection: states) = .merge(:as => :string) if states.class == String end |
.states_collection(f, options) ⇒ Object
Return either the State (String) or States (Array)
22 23 24 25 26 |
# File 'lib/country_state_select.rb', line 22 def self.states_collection(f, ) states = collect_states(f.object.send([:country])) return f.object.send([:state]) if states.size == 0 states end |