Inside my main Extensi开发者_Python百科on I have this standard way of instantiating a Calculator. This module is part of the preinitializing process of Spree :
module AgedRevolt
class Engine < Rails::Engine
config.autoload_paths += %W(#{config.root}/lib)
def self.activate
Dir.glob(File.join(File.dirname(__FILE__), "../app/**/*_decorator*.rb")) do |c|
Rails.env.production? ? require(c) : load(c)
end
Calculator::PerWeight.register
end
config.to_prepare &method(:activate).to_proc
end
end
Then when I run the server I get this:
app/models/calculator/per_weight.rb:16:in `register': uninitialized constant Calculator::PerWeight::Coupon (NameError)
So I try and run them independently and get this:
ruby-1.8.7-p330 :002 > Coupon
NameError: uninitialized constant Coupon
from (irb):2
ruby-1.8.7-p330 :003 > ShippingRate
NameError: uninitialized constant ShippingRate
from (irb):3
What could that be from?
Here's what I did
In my main extension gem :
def self.activate
Dir.glob(File.join(File.dirname(__FILE__), "../app/**/*_decorator*.rb")) do |c|
Rails.env.production? ? require(c) : load(c)
end
Calculator::PerWeight.register
end
In my custom calculator:
def self.register
super
ShippingMethod.register_calculator(self)
end
精彩评论