Hey, how do I set a scope in rails 3 to todays records?
This doent work, yet. I get no data.
class MyModel < ActiveRecord::Base
scope :today, :con
I think you can define a general scope like this:
class MyModel < ActiveRecord::Base
scope :created_on, lambda {|date| {:conditions => ['created_at >= ? AND created_at <= ?', date.beginning_of_day, date.end_of_day]}}
def self.today
self.created_on(Date.today)
end
end
So you can use
>> MyModel.today #-> records created today
>> MyModel.created_on(Date.today - 1.week) #-> records created a week ago