How do I validate one post per day?

后端 未结 2 1635
不知归路
不知归路 2021-01-24 02:53

I am trying to create a validation to ensure one post per day, 24hrs starting from 00:00. How can this be done in Rails please?

I did the following but I am not sure whe

2条回答
  •  自闭症患者
    2021-01-24 03:12

    That error is because today is instance method of model, not a scope.

    What you need is scope:

     scope :today, lambda{ where(:created_at => (Time.now.beginning_of_day..Time.now)) }
    

提交回复
热议问题