开发者

Rails, production-env, "Object is not missing constant"

So I seems I was stupid and haven't checked running in production-env for a long time, and now that I'm trying to deploy, I'm getting this annoying error. Any ideas?

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

app/models/user.rb

class User < InheritedResources::Base
  include HistoryTools
end

config/environment.rb

# ... the usual stuff, then, at the very bottom:
require 'history_tools'

This gives the error:

activesupport-2.3.8/lib/active_support/dependencies.rb:417:in
`load_missing_constant':ArgumentError: Object is not missing
 constant HistoryTools!

If I add an additional require 'history_tools' at the top of user.rb, it fixes that error, I believe, but then it fails at finding other thing开发者_运维技巧s in #{RAILS_ROOT}/lib, that were required in the environment.rb in the same manner.

The kicker: this works perfectly in development mode. It only gives this error in production. Most of my googling seems to suggest that "not missing constant" errors relates to how Rails autoloads files, which should go away in production when nothing is unloaded. This seems to be the opposite of that behavior?


When I've gotten this error, it's because there's an error in an inner class/module that's inside the class/module mentioned in the error.


I can't say if this is a typo or the real code but:

class User < InheritedResources::Base
  include HistoryTools
end

Should probably be

class User < ActiveRecord::Base
  include HistoryTools
end

InheritedResources should be used for controllers, not models.


You shouldn't have to have the require 'history_tools' in the environment.rb. In that version of Rails all files in the lib folder should be auto-loaded.


ok, after many more hours of digging, it seems it wasn't even related to this stuff at all. It was an error about 3 more classes down the tree, that was failing for another strange reason, and the exception was apparently being caught by the internals of rails somewhere and just ignored.

That doesn't explain why it worked in development mode, unfortunately, but at least all my stuff works now. Thanks anyway!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜