Anyone know the best query to find records created THIS month in Rails 3.1?
class Model
scope :this_month, -> { where(created_at: Time.now.beginning_of_month..Time.now.end_of_month) }
end
you can call it like this:
Model.this_month
I prefer SQL-less:
Model.where(:created_at => Time.now.beginning_of_month..Time.now.end_of_month)
or as a scope:
class Model < ActiveRecord::Base
scope :this_month, -> { where(:created_at => Time.now.beginning_of_month..Time.now.end_of_month) }
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With