问题
I have a tiny rake task which just sticks a new delayed job into the queue. I've inserted a debug line
desc 'Start processing new rss feed articles'
task :process_new_articles => :environment do
config = RSS_CONFIG
feeds = config['rss_feeds']
puts Article.all
feeds.each do |feed|
Delayed::Job.enqueue ProcessNewArticlesJob.new(feed, config['settings'])
end
end
It seems to be loading the config info correctly. But I'm getting a "uninitialized constant Article" error upon running the task. Article is a MongoMapper model. I've verified the connection to the database (on MongoLab) works fine.
This all works great locally.
--
What is even more bizarre is that referencing Article.all using "heroku run console" works just fine.
--
The stack trace doesn't show much:
2011-12-04T22:33:02+00:00 app[start.1]: rake aborted!
2011-12-04T22:33:02+00:00 app[start.1]: uninitialized constant Article
回答1:
Found the problem and it is totally weird.
I had accidentally named my Article model file, "Article.rb" with a capital A. This caused Heroku to not pick up on it upon running "rake environment".
Strange and most likely a bug?
来源:https://stackoverflow.com/questions/8379079/heroku-rake-task-uninitialized-constant-for-mongomapper-model