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
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)) }
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