Search code examples
ruby-on-railsruby-on-rails-3ruby-on-rails-3.1

How to find records created this month in Rails 3.1?


Anyone know the best query to find records created THIS month in Rails 3.1?


Solution

  • 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