In my models/book.rb I have this
def created_since?(number_of_days)
(Date.current - created_at.to_date).to_i <= number_of_days
end
That is used in view files like
<% if @book.created_since?(30) %>
Can I optimize it editing with something like this?
def created_since?(number_of_days)
number_of_days.days.ago.to_date
end
Is it a good idea? will it work the same?
Aucun commentaire:
Enregistrer un commentaire