Rails 生产中未初始化常量
我有一个奇怪的问题。在开发中,这个问题不存在,但在生产中,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['PROGRAMME']['PROGRAMME_ID']])
I have a weird problem. In development this problem does not exist, but in production rake throws this error message at me "uninitialized constant Program"
The "Program" is an active record model, and it's there, it's in the schema file and it's in the app/model folder.
I execute it like this rake import:xml RAILS_ENV=production. What could be the problem? Below is the full stack trace
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
Line 18: program = Program.find(:first, :conditions => ['programident = ?', broadcast['PROGRAMME']['PROGRAMME_ID']])
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试一下
,或者如果您需要大部分模型,
Rake 不会急于加载您的模型。
在这里查看一个很好的解释 Rails 3 rake 任务找不到模型生产中
Try
or if you need most of your models
Rake doesn't eager load your models.
See a good explanation here Rails 3 rake task can't find model in production
您可能忘记了您的任务取决于:环境。
已编辑!可能不是正确的答案,看看急切加载的答案。
You've probably forgotten to depend your task on :environment.
EDITED! Probably not the right answer look at the answer with the eager loading.