views:

56

answers:

1

I'm creating a simple paste-bin in Ruby on Rails, which will have an expire-feature. With this, people can select a date when the paste will be deleted automatically. How can I implement this? I was thinking of a cronjob, but maybe there is a more platform-independent way, by defining this in the model itself. Can anyone help me? Thanks.

+1  A: 

cron will work fine. You can make a Rake task that performs the actual deletions, and then trigger that from cron.

Alternatively, you could keep the data forever and simply quit showing any records that have expiration dates in the past.

jdl
I haven't thought of the second option. That one is actually greater than great! It will be more HTTP'ish, since I can use the right status-codes for permanently deleted resources, and some more things. Thanks!
Time Machine
And it's also good for spam-recognation if I keep all spam-pastes in the DB. A paste-bin is namely a spammer's-heaven ;)
Time Machine
you may also want to check out the whenever gem, see http://railscasts.com/episodes/164-cron-in-ruby
neutrino