升级到Rails 3.2后,我的rake任务无法自动加载模型。
以下是在rails 3.1中工作:
09:04:14 /srv/www/gamersmafia/current$ rake --trace gm:update_default_skin_styles
rake aborted!
No such file to load -- notification
/usr/lib/ruby/gems/1.8/gems/activesupport-3.2.1/lib/active_support/dependencies.rb:317:in `depend_on'
/usr/lib/ruby/gems/1.8/gems/activesupport-3.2.1/lib/active_support/dependencies.rb:225:in `require_dependency'
/usr/lib/ruby/gems/1.8/gems/railties-3.2.1/lib/rails/engine.rb:439:in `eager_load!'
/usr/lib/ruby/gems/1.8/gems/railties-3.2.1/lib/rails/engine.rb:438:in `each'
/usr/lib/ruby/gems/1.8/gems/railties-3.2.1/lib/rails/engine.rb:438:in `eager_load!'
/usr/lib/ruby/gems/1.8/gems/railties-3.2.1/lib/rails/engine.rb:436:in `each'
/usr/lib/ruby/gems/1.8/gems/railties-3.2.1/lib/rails/engine.rb:436:in `eager_load!'
/srv/www/gamersmafia/current/lib/tasks/update_games_and_factions_sprite.rake:1
/usr/lib/ruby/gems/1.8/gems/activesupport-3.2.1/lib/active_support/dependencies.rb:245:in `load'
/usr/lib/ruby/gems/1.8/gems/activesupport-3.2.1/lib/active_support/dependencies.rb:245:in `load'
/usr/lib/ruby/gems/1.8/gems/activesupport-3.2.1/lib/active_support/dependencies.rb:236:in `load_dependency'
/usr/lib/ruby/gems/1.8/gems/activesupport-3.2.1/lib/active_support/dependencies.rb:245:in `load'
/usr/lib/ruby/gems/1.8/gems/railties-3.2.1/lib/rails/engine.rb:425:in `load_tasks'
/usr/lib/ruby/gems/1.8/gems/railties-3.2.1/lib/rails/engine.rb:425:in `each'
/usr/lib/ruby/gems/1.8/gems/railties-3.2.1/lib/rails/engine.rb:425:in `load_tasks'
/usr/lib/ruby/gems/1.8/gems/railties-3.2.1/lib/rails/application.rb:145:in `load_tasks'
/usr/lib/ruby/gems/1.8/gems/railties-3.2.1/lib/rails/railtie/configurable.rb:30:in `send'
/usr/lib/ruby/gems/1.8/gems/railties-3.2.1/lib/rails/railtie/configurable.rb:30:in `method_missing'
/srv/www/gamersmafia/current/Rakefile:7
/usr/lib/ruby/gems/1.8/gems/rake-0.9.2.2/lib/rake/rake_module.rb:25:in `load'
/usr/lib/ruby/gems/1.8/gems/rake-0.9.2.2/lib/rake/rake_module.rb:25:in `load_rakefile'
/usr/lib/ruby/gems/1.8/gems/rake-0.9.2.2/lib/rake/application.rb:501:in `raw_load_rakefile'
/usr/lib/ruby/gems/1.8/gems/rake-0.9.2.2/lib/rake/application.rb:82:in `load_rakefile'
/usr/lib/ruby/gems/1.8/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/usr/lib/ruby/gems/1.8/gems/rake-0.9.2.2/lib/rake/application.rb:81:in `load_rakefile'
/usr/lib/ruby/gems/1.8/gems/rake-0.9.2.2/lib/rake/application.rb:65:in `run'
/usr/lib/ruby/gems/1.8/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/usr/lib/ruby/gems/1.8/gems/rake-0.9.2.2/lib/rake/application.rb:63:in `run'
/usr/lib/ruby/gems/1.8/gems/rake-0.9.2.2/bin/rake:33
/usr/local/bin/rake:19:in `load'
/usr/local/bin/rake:19
我的应用的代码是开源的,所以你可以在这里查看:
https://github.com/slnc/gamersmafia
我所做的唯一修改是添加
“Rails.application.eager_load!”行到上面显示的rake任务的开头。没有它,就不会加载“Skins”库。
UPDATE 我尝试通过在上面显示的堆栈跟踪的每一行上添加puts语句来调试它,我可以看到类似这样的内容:
eager_load_path: /srv/www/gamersmafia/current/app/mailers
file found: /srv/www/gamersmafia/current/app/mailers/notification.rb
require_dependency notification
... notification
rake aborted!
这大致似乎表明rails正在查找notification.rb文件,但是当它尝试加载它时却不能。
答案 0 :(得分:0)
gem install notification
可能就是这样做,因为No such file to load -- notification
表示require 'notification'
失败。