1

我正在使用friendly_id gem。有一个删除旧 slug 的 rake 任务(来自文档):

rake friendly_id:remove_old_slugs MODEL=<model name> DAYS=<days>

它可以通过cron运行。

你知道它应该如何添加到 cron.rake(我在 Heroku)吗?

这是我的 cron.rake:

desc "This task is called by the Heroku cron add-on"
task :cron => :environment do

  ...
  rake friendly_id:remove_old_slugs

end

它产生一个错误:

"rake aborted! undefined method `friendly_id' for main:Object"

如果我像这样从控制台(终端)运行它,则没有错误:

heroku rake friendly_id:remove_old_slugs
4

1 回答 1

2

尝试这个:

desc "This task is called by the Heroku cron add-on"
task :cron => :environment do
  Rake::Task['friendly_id:remove_old_slugs'].execute
end
于 2011-05-31T10:56:55.180 回答