Howto: Model scope for todays records

后端 未结 5 1352
后悔当初
后悔当初 2021-02-08 05:03

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         


        
5条回答
  •  孤城傲影
    2021-02-08 05:36

    I know that is a old question, but still can help anyone.

    This was my way to solve this:

    scope :today, -> { where(created_at: DateTime.now.beginning_of_day..DateTime.now.end_of_day) }

提交回复
热议问题