【问题标题】:What's the best method for automatically deleting users posts in Rails?在 Rails 中自动删除用户帖子的最佳方法是什么?
【发布时间】:2013-03-20 21:43:29
【问题描述】:

我正在创建一个列表类型的 Web 应用程序,并且希望用户的帖子在帖子/列表过期后的某个时间自动删除?

更详细地介绍您发布的应用程序,假设您将乘坐汽车升降机将某人带到目的地。我希望帖子在提升完成 24 小时后自行删除

rails 的 cronjob/scheduler 是唯一的方法吗?没有更简单的方法吗?

我很难理解它。

下面是代码:lib/tasks/scheduler.rake

desc "This task is called by the Heroku scheduler add-on"


task :delete_hosting => :environment do
 => not sure what goes here, something like => User.host.after_time.delete? //
end

谢谢

【问题讨论】:

    标签: ruby-on-rails cron scheduled-tasks


    【解决方案1】:

    Resque-Scheduler 与该功能完美匹配:https://github.com/bvandenbos/resque-scheduler

    Resque.enqueue_in(1.day, DeleteUserPost, :user_post_id => user_post.id)
    

    在 DeleteUserPost 中,您编写删除 UserPost 的代码

    【讨论】:

      猜你喜欢
      • 2013-03-16
      • 1970-01-01
      • 2020-12-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-01-02
      • 2011-10-03
      • 2010-09-09
      相关资源
      最近更新 更多