What is the best way to set a database entry so that it expires after n hours using Ruby/Rails?

Posted by marcgg on Stack Overflow See other posts from Stack Overflow or by marcgg
Published on 2010-06-16T14:12:41Z Indexed on 2010/06/16 14:22 UTC
Read the original article Hit count: 531

My app has a token model as such:

class Token < ActiveRecord::Base
  # The model include a few attributes including created_at
end

I want entries linked to this model to expire after 6 hours, meaning that they should get automatically deleted.

I know that I could set a cronjob or something similar to do this, but isn't there a better/simpler way?

Note: I'm using Rails 3.0.0beta3, mysql (in dev) and postgres (in prod)

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about ruby