views:

30

answers:

3

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 things 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?

A: 

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.

r-dub
A: 

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.

Maran
you're correct, of course. I've been writing way too many controller recently and typed that out of habit... *sigh*
pdkl95
A: 

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!

pdkl95
It probably worked in dev mode because you didn't access that class that had the error. When you start the server in production mode it pre-loads all the classes so the errors become much more apparent.
r-dub