1

I'm building an app where users can decide when their posts will be deleted, but I don't know how to do it in Rails 3.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Sudoman
  • 31
  • 5

3 Answers3

1

As far as I know you will have to use cron.

Oded Harth
  • 4,367
  • 9
  • 35
  • 62
1

Sometimes you can inactivate a post rather than executing the database command "delete". If you inactivate, then you'll keep statistics and comments.

class Post
  attr_protected :published_on, :deleted_on
  belongs_to :user
  scope :published, lambda{ where("published_on >= ?", Time.now).where("deleted_on IS NULL or deleted_at < ?", Time.now)}

end

in your controller later:

@posts = @user.posts.published.paginate(params[:page])
Jesse Wolgamott
  • 40,197
  • 4
  • 83
  • 109
0

I assume you want the posts to be automatically deleted on a certain date(time) and your users are able to set that date(time). To achieve that you must use cron jobs. Here you can find more about it.

Another (real dirty) solution is to execute a method each time your app is accessed and look for the posts that needed to be deleted.

Community
  • 1
  • 1
Ivan
  • 874
  • 10
  • 32