Rails 生产中未初始化常量

发布于 2024-10-08 18:13:59 字数 2286 浏览 9 评论 0原文

我有一个奇怪的问题。在开发中,这个问题不存在,但在生产中,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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

晌融 2024-10-15 18:13:59

尝试一下

require 'app/models/program'

,或者如果您需要大部分模型,

Rails.application.eager_load!

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

在这里查看一个很好的解释 Rails 3 rake 任务找不到模型生产中

Try

require 'app/models/program'

or if you need most of your models

Rails.application.eager_load!

Rake doesn't eager load your models.

See a good explanation here Rails 3 rake task can't find model in production

怪我入戏太深 2024-10-15 18:13:59

您可能忘记了您的任务取决于:环境。

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

已编辑!可能不是正确的答案,看看急切加载的答案。

You've probably forgotten to depend your task on :environment.

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

EDITED! Probably not the right answer look at the answer with the eager loading.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文