Rails在生产中未初始化不变

时间:2010-12-22 08:29:59

标签: ruby-on-rails passenger rake-task

我有一个奇怪的问题。在开发中这个问题不存在,但是在生产中rake将这个错误消息抛给我“未初始化的常量程序”

“程序”是一个活动的记录模型,就在那里,它位于模式文件中,位于app / model文件夹中。

我执行它就像这个rake import:xml RAILS_ENV = production。可能是什么问题呢?下面是完整的堆栈跟踪

rake import:xml RAILS_ENV=production --trace
(in /usr/mobloom/www/htdocs/remindertest)
** Invoke import:xml (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute import:xml
rake aborted!
uninitialized constant Program
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2503:in `const_missing'
/usr/lib/ruby/gems/1.8/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:92:in `const_missing'
/usr/mobloom/www/htdocs/remindertest/lib/tasks/import_assets.rake:18
/usr/mobloom/www/htdocs/remindertest/lib/tasks/import_assets.rake:9:in `each'
/usr/mobloom/www/htdocs/remindertest/lib/tasks/import_assets.rake:9
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:636:in `call'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:636:in `execute'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:631:in `each'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:631:in `execute'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:597:in `invoke_with_call_chain'
/usr/lib/ruby/1.8/monitor.rb:242:in `synchronize'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:590:in `invoke_with_call_chain'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:583:in `invoke'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2051:in `invoke_task'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in `top_level'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in `each'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in `top_level'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2068:in `standard_exception_handling'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2023:in `top_level'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2001:in `run'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2068:in `standard_exception_handling'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:1998:in `run'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/bin/rake:31
/usr/bin/rake:19:in `load'
/usr/bin/rake:19

第18行:program = Program.find(:first,:conditions => ['programident =?',broadcast ['PROGRAM'] ['PROGRAMME_ID']])

2 个答案:

答案 0 :(得分:5)

尝试

require 'app/models/program'

或者如果您需要大多数模型

Rails.application.eager_load!

Rake并不急于加载您的模型。

在这里查看一个很好的解释Rails 3 rake task can't find model in production

答案 1 :(得分:-1)

你可能忘记了依赖任务:环境。

task :xml => :environment do
  ...code here...
end

EDITED!可能没有正确的答案通过热切的加载来看答案。