ruby-on-rails – 生产佣金任务不承认我的模型

前端之家收集整理的这篇文章主要介绍了ruby-on-rails – 生产佣金任务不承认我的模型前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
当我运行Heroku Bamboo时,这从来都不是问题.现在,在Cedar上,每当我尝试从服务器上的rake任务中访问我的模型时,我都会收到错误. rake db:seed,标准rake任务以及我自己的自定义构建任务明确包括:environment.我甚至多余地这样做:
namespace :db do
  desc "Update db"
  task :new_seed => :environment do
    require './Scraped_Data/Games/code/column-headers.rb'
    require 'csv'
    require 'net/http'
    require './config/environment.rb'

    # code here...

  end
end

我在其他地方找不到任何关于这个问题的提及,所有这些任务都在开发中完美运行.感谢您的任何见解,这里是完整的错误消息,一旦他们在Heroku上遇到我的模型,rake任务就会吐出来:

rake aborted!
uninitialized constant Object::Movie
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/ext/module.rb:36:in `const_missing'
/app/lib/tasks/new_seed.rake:187:in `block in load_scraped_data'
/app/vendor/bundle/ruby/1.9.1/gems/rest-open-uri-1.0.0/lib/rest-open-uri.rb:37:in `open'
/app/vendor/bundle/ruby/1.9.1/gems/rest-open-uri-1.0.0/lib/rest-open-uri.rb:37:in `open'
/app/lib/tasks/new_seed.rake:148:in `load_scraped_data'
/app/lib/tasks/new_seed.rake:550:in `block (2 levels) in <top (required)>'
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `call'
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `block in execute'
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `each'
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `execute'
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:158:in `block in invoke_with_call_chain'
/usr/local/lib/ruby/1.9.1/monitor.rb:201:in `mon_synchronize'
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:151:in `invoke_with_call_chain'
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:144:in `invoke'
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:116:in `invoke_task'
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `block (2 levels) in top_level'
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `each'
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `block in top_level'
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:88:in `top_level'
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:66:in `block in run'
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:63:in `run'
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/bin/rake:33:in `<top (required)>'
/app/vendor/bundle/ruby/1.9.1/bin/rake:19:in `load'
/app/vendor/bundle/ruby/1.9.1/bin/rake:19:in `<main>'
Tasks: TOP => db:new_seed

解决方法

默认情况下,线程安全设置dependency_loading = false
如果要在应用程序中启用线程安全并在任务中访问模型,则需要加载它.
# Enable threaded mode
config.threadsafe!
config.dependency_loading = true if $rails_rake_task

参考:http://nowhereman.github.com/how-to/rails_thread_safe/

希望这有帮助!

原文链接:https://www.f2er.com/ruby/268748.html

猜你在找的Ruby相关文章