Created
October 13, 2013 22:03
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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