How do I validate one post per day?

后端 未结 2 1615
不知归路
不知归路 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:23

    You shoud use scopes for that:

    class Article
      scope :today, -> { where(:created_at => (Time.now.beginning_of_day..Time.now.end_of_day)) }
    end
    

    http://apidock.com/rails/ActiveRecord/NamedScope/ClassMethods/scope

提交回复
热议问题