Heroku rake task uninitialized constant for MongoMapper model

坚强是说给别人听的谎言 提交于 2019-12-11 03:08:54

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!