修改订单模型的问题:未初始化的常量订单(NameError) - Spree 0.60.1



这是我在列表上的第一篇文章,但在我寻求帮助之前,我想感谢你们所有人创建的精彩平台。

在我正在做的一个项目上,有一个捐赠/捐赠功能的需要。我已经按照定制指南(http://spreecommerce.com/documentation/customization.html)向Order模型添加了新的逻辑。

我添加了一个名为"order_decorator"的新文件。Rb ' inside 'app/models'并添加:

Order.class_eval do
  def my_method
    # custom code
  end
end

,我得到以下错误:

order_decorator.rb:1:in `<top (required)>': uninitialized constant Order (NameError)
谁能给我的问题加点光?

这是在Spree邮件列表中交叉发布的https://groups.google.com/d/topic/spree-user/mGcj4EpGuYo/discussion

感谢Brian (https://groups.google.com/forum/#!topic/spree-user/mGcj4EpGuYo/discussion)的修复。在spree中,require语句需要添加所有以'_decorator'结尾的文件,需要放入'self '中。激活的块:

module SpreeSite
  class Engine < Rails::Engine
    def self.activate
      # Add your custom site logic here
      Dir.glob(File.join(File.dirname(__FILE__), "../app/**/*_decorator*.rb")) do |c|
        Rails.configuration.cache_classes ? require(c) : load(c)
      end
      AppConfiguration.class_eval do
       #
      end
    end
    def load_tasks
    end
    config.to_prepare &method(:activate).to_proc
  end
end

这破坏了Rails的命名方案。将文件名更改为order。

最新更新