Skip to content

Instantly share code, notes, and snippets.

@sirramongabriel
Created October 13, 2013 22:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sirramongabriel/6967896 to your computer and use it in GitHub Desktop.
Save sirramongabriel/6967896 to your computer and use it in GitHub Desktop.
Demonstrates that scopes were added to my model, instead of tacking on methods before iteration through future/past events
class Event < ActiveRecord::Base
attr_accessible :event_at, :attendance_limit, :price, :name, :description,
:signup_count, :signup_deadline
belongs_to :venue
has_many :attendances, dependent: :destroy
has_many :users, through: :attendances
scope :future, -> { where("event_at > ?", Time.now) }
scope :past, -> { where("event_at < ?", Time.now) }
validates :event_at, presence: true
validates :attendance_limit, presence: true
validates :price, presence: true
validates :name, presence: true
validates :signup_deadline, presence: true
def attendee_count
attendances.size
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment