Skip to content

Instantly share code, notes, and snippets.

@dtrasbo
Created January 9, 2011 13:09
Show Gist options
  • Save dtrasbo/771668 to your computer and use it in GitHub Desktop.
Save dtrasbo/771668 to your computer and use it in GitHub Desktop.
class Person < ActiveRecord::Base
belongs_to :country
scope :minor, proc { where('birthday >= ?', 18.years.ago) }
scope :adult, proc { where('birthday <= ?', 18.years.ago) }
scope :male, where(gender: 'male')
scope :female, where(gender: 'female')
def self.living_in(country)
joins(:country).where('countries.name = ?', country)
end
end
people = Person.minor.male.living_in('Spain')
people.order(:birthday).each do |person|
# ...
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment