Howto: Model scope for todays records

后端 未结 5 1353
后悔当初
后悔当初 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:30

    IMO this is the most understandable way to do it.

      def self.created_today
        where("created_at >= ? AND created_at < ?", Date.today, Date.tomorrow)
      end
    

提交回复
热议问题