0

在我的主要扩展中,我有这种实例化计算器的标准方法。该模块是 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

然后当我运行服务器时,我得到了这个:

app/models/calculator/per_weight.rb:16:in `register': uninitialized constant Calculator::PerWeight::Coupon (NameError)

所以我尝试独立运行它们并得到这个:

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

那可能来自什么?

4

1 回答 1

0

这就是我所做的

在我的主要扩展 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

在我的自定义计算器中:

def self.register
  super
  ShippingMethod.register_calculator(self)
end
于 2011-03-03T21:57:18.797 回答