Martin Petrov
Martin Petrov

Reputation: 2643

Heroku, cron.rake and friendly_id gem

I'm using the friendly_id gem. There's a rake task for deleting old slugs (from the docs):

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

It can be run via cron.

Do you know how it should be added to cron.rake (I'm on Heroku)?

Here is my cron.rake:

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

  ...
  rake friendly_id:remove_old_slugs

end

It produces an error:

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

There is no error if I run it from the console (Terminal) like this:

heroku rake friendly_id:remove_old_slugs

Upvotes: 1

Views: 406

Answers (1)

Kris
Kris

Reputation: 2128

Try this:

desc "This task is called by the Heroku cron add-on"
task :cron => :environment do
  Rake::Task['friendly_id:remove_old_slugs'].execute
end

Upvotes: 2

Related Questions