Error with overwriting Ruby class only manifests itself in production?
I recently ran into an odd error that only occurred in production mode.
I was using the paths of glory gem that defines the class Achievement (http://github.com/paulca/paths_of_glory/blob/master/app/models/achievement.rb).
In the base class, level is defined:
def level(level, options = {})
levels << {:level => level, :quota => options[:quota]}
end
The paths of gl开发者_运维百科ory gem works by having you create models that inherit from the base achievement model.
In an effort to add an additional method to the base Achievement class, we (erroneously, in retrospect) created a new models/aachievements.rb (yes, intentional spelling error, since Rails will try to load Achievement if we called it achievements.rb) file, however, rather than re-opening the class, we redefined the class. Because our redefinition didn't include level, when we deployed to production, we hit an error that level was an undef method.
The question is, why didn't this error manifest itself in development mode? The gem and classes were the same in both.
Any ideas?
Unless you namespaced or deleted the constant you really still reopened the class, or yours was defined first then reopened by the gem.
Anyways, turn on cache classes in development.rb in environments and see what happens.
精彩评论