Let’s say you have a Rails application that uses fragment caching and the rendering of one of your models is dependent on the current time, in addition to the stored attribute values in the database.As an example let’s say we are selling deals, and our deal expires after 24 hours.
This is probably bad; it would be better to make regular fields to contain the data we are trying to conditionally shoehorn into the timestamp.
When converting something in a project, I found that I needed to updated a field for every record in a Request table.
I have embedded discourse in my blog, and it has been automagically generating topics for each post in the blog as the blog pages get accessed.
This is great, but it looks like new content when in fact it's an archive of posts and should not be so prominent in the forums.
Note: This article was written by Andreas Garnæs of Subsis, one of our awesome partners.
The default Active Record cache key implementation only takes the model’s attributes into account, not what the current time is.If your model changes with the passing of time – e.g.a deal that expires – using the default correctly to handle models that will change state automatically at a future time.An unrelated update that was supposed to stamp, but occurred exactly between the true/false flip, would not stamp correctly.This is true even if it’s in another class, since the , and use to temporarily reparent the instance for the duration of the save (I hope that last suggestion made you gag). If we set up our callbacks properly, we can let anyone update is changed (because otherwise timestamps really do need to happen).I know how to open the ruby console and how to open the JS console.