Heroku,cron.rake和friendly_id gem

时间:2011-05-31 08:33:45

标签: ruby-on-rails friendly-id

我正在使用friendly_id gem。 删除旧slu(from the docs)有一个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

1 个答案:

答案 0 :(得分: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