Rails,production-env,“Object is not missing constant”
所以我似乎是愚蠢的,并没有检查生产env运行很长一段时间,现在我正在尝试部署,我得到这个恼人的错误。 有任何想法吗?
LIB / history_tools.rb
module HistoryTools def self.included(base) base.has_many :history, :dependent => :destroy History::TYPES.each do |htype| base.has_many "history_#{htype}", :class_name => "History::#{htype.capitalize}" end end # ... other minor things removed ... end
应用程序/模型/ user.rb
class User < InheritedResources::Base include HistoryTools end
到config / environment.rb
# ... the usual stuff, then, at the very bottom: require 'history_tools'
这给出了错误:
activesupport-2.3.8/lib/active_support/dependencies.rb:417:in `load_missing_constant':ArgumentError: Object is not missing constant HistoryTools!
如果我在user.rb的顶部添加一个额外require 'history_tools'
,它会修复该错误,我相信,但是它在找到#{RAILS_ROOT}/lib
其他东西时失败了,这在环境中是必需的.rb in以同样的方式。
踢球者:这在开发模式下完美运行。 它只会在生产中出现此错误。 我的大部分谷歌搜索似乎表明“不丢失常量”错误与Rails如何自动加载文件有关,当没有任何内容卸载时,这些文件应该在生产中消失。 这似乎与这种行为相反?
当我收到此错误时,这是因为错误中提到的类/模块内部类/模块中存在错误。
我不能说这是一个拼写错误还是真正的代码,但是:
class User < InheritedResources::Base include HistoryTools end
应该是
class User < ActiveRecord::Base include HistoryTools end
InheritedResources应该用于控制器,而不是模型。
您不必在environment.rb中具有require’ranch_tools’。 在该版本的Rails中,应该自动加载lib文件夹中的所有文件。
好吧,经过多个小时的挖掘后,它似乎根本就与这些东西无关。 这是一个错误,关于树下3个以上的类,这是因为另一个奇怪的原因而失败,并且exception显然被某个地方的轨道内部捕获而被忽略了。
不幸的是,这并没有解释为什么它在开发模式下工作,但至少现在我的所有东西都能正常工作。 不管怎么说,还是要谢谢你!
- Omniauth:回调未触发,返回失败并显示“无效凭据”
- 将额外数据添加到连接表 – Rails
- Rake Aborted,在add_index(:users,:email,{:unique => true})
- 没有路由匹配{:action =>“show”,:controller =>“schools”}缺少必需的键:
- 带参数的Rails helper_method
- 获取Devise身份validation以发送用于密码检索的电子邮件
- 回调后的`attribute_changed?`的行为将会改变
- Capistrano部署到同一个Cloud Service上的许多节点
- Ruby On Rails:为环境创建不同种子文件的方法