I would define define two things on your Event model: expired
scope, and expired?
method:
class Event < AR::Base
scope :expired, -> { where('eventdate < ?', Date.today) }
def expired?
eventdate < Date.today
end
end
To list all expired events you can simply call:
Event.expired
If you are listing all the events and want to add some custom logic for expired one, you can wrap this logic in if event.expired?
.
You probably also should inverse scope as well:
scope :not_expired, -> { where.not('eventdate < ?', Date,today) }