Class: Country

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/country.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.find_countries_with_metrosObject



12
13
14
# File 'app/models/country.rb', line 12

def self.find_countries_with_metros
  Country.joins(:metro_areas).where('metro_areas.id IS NOT NULL').order('countries.name ASC').to_a.uniq
end

.get(name) ⇒ Object



4
5
6
7
8
9
10
# File 'app/models/country.rb', line 4

def self.get(name)
  case name
    when :us
      c = 'United States'
  end
  self.find_by_name(c)
end

Instance Method Details

#metro_area_idsObject



20
21
22
# File 'app/models/country.rb', line 20

def metro_area_ids
  metro_areas.map{|m| m.id }.to_ary
end

#statesObject



16
17
18
# File 'app/models/country.rb', line 16

def states
  State.joins(:metro_areas).where("metro_areas.id in (?)", metro_area_ids ).order('states.name ASC').to_a.uniq
end