I am creating a CourseEnrollment model and whenever a user views the course, I want to update the database with the current timestamp. Should I just update the existing updated_at field or create a seperate field for the model?
Check out the AR touch
method http://api.rubyonrails.org/classes/ActiveRecord/Persistence.html#method-i-touch
I'd create a separate field. updated_at
doesn't really correctly communicate its purpose. Something like last_viewed_at
would be more appropriate. Of course, updated_at
will be updated when you update last_viewed_at
, so you need to find a way to override that when all you want to do is update that column.
You can temporarily disable timestamp updating by setting self.record_timestamps
to false in a before_filter
and then re-enabling it in an after_filter
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With