I'm pretty new to Rails and for the first time, I want to use Heroku Scheduler to run periodical tasks in my rails application. As advised in the Tutorial, I created the following rake tasks in /lib/tasks/scheduler.rake
desc "This task is called by the Heroku scheduler add-on"
task :auto_results => :environment do
puts "Updating results..."
@cups = Cup.all
@cups.each do |cup|
cup.fix_current_results
end
puts "done."
end
task :update_game_dates => :environment do
puts "Updating game dates..."
@cups = Cup.all
@cups.each do |cup|
cup.update_game_dates
end
puts "done."
end
The task run fine in my local environment, but after pushin to Heroku and running the task, each abort with the following error:
rake aborted!
undefined method `name' for nil:NilClass
To me it seems that Heroku somehow can't access the database and so doesn't revieve an object on which it can perform methods.
Ideas anyone?