Sha256: 845713ce29cd2e397e032254370c02bac0815a2811da7450d8f5eae59b53798c

Contents?: true

Size: 565 Bytes

Versions: 5

Compression:

Stored size: 565 Bytes

Contents

class Country < ActiveRecord::Base
  has_many :metro_areas

  attr_accessible :name
  
  def self.get(name)
    case name
      when :us
        c = 'United States'
    end
    self.find_by_name(c)
  end
  
  def self.find_countries_with_metros
    Country.joins(:metro_areas).where('metro_areas.id IS NOT NULL').order('countries.name ASC').all.uniq
  end
  
  def states
    State.joins(:metro_areas).where("metro_areas.id in (?)", metro_area_ids ).order('states.name ASC').all.uniq
  end
  
  def metro_area_ids
    metro_areas.map{|m| m.id }.to_ary
  end
  
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
community_engine-2.3.2 app/models/country.rb
community_engine-2.3.1 app/models/country.rb
community_engine-2.3.0 app/models/country.rb
community_engine-2.1.0 app/models/country.rb
community_engine-2.0.0 app/models/country.rb