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

发布于 2024-12-04 17:13:08 字数 661 浏览 2 评论 0原文

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

在我正在从事的一个项目中,需要捐赠/捐赠功能。我已按照自定义指南 (http://spreecommerce.com/documentation/customization.html) 向订单模型添加新逻辑。

我在“app/models”中添加了一个名为“order_decorator.rb”的新文件并添加:

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/讨论

This is my first post on the list but before I ask for help I would to thank you all for the wonderful platform that you have created.

On a project I'm working on there is a need for a donation/donate functionality. I've followed the customization guide (http://spreecommerce.com/documentation/customization.html) to add new logic to the Order model.

I've added a new file called 'order_decorator.rb' inside 'app/models' and added:

Order.class_eval do
  def my_method
    # custom code
  end
end

and I'm getting the following error:

order_decorator.rb:1:in `<top (required)>': uninitialized constant Order (NameError)

Anyone can add some light to my problem?

This was cross posted the Spree mailing list https://groups.google.com/d/topic/spree-user/mGcj4EpGuYo/discussion

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

百变从容 2024-12-11 17:13:08

谢谢布莱恩 (https://groups.google.com/forum/ #!topic/spree-user/mGcj4EpGuYo/discussion) 进行修复。在 spree 中,添加所有以 '_decorator' 结尾的文件所需的 require 语句需要进入 'self.activate' 块内部:

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

Thanks Brian (https://groups.google.com/forum/#!topic/spree-user/mGcj4EpGuYo/discussion) for the fix. In spree the require statement needed to add all the files that end with '_decorator' need to go inside the 'self.activate' block:

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
噩梦成真你也成魔 2024-12-11 17:13:08

这破坏了 Rails 命名方案。将文件名更改为 order.rb 或将代码更改为 OrderDecorator.class_eval do ...

That is breaking the Rails naming scheme. Either change the file name to order.rb or the code to OrderDecorator.class_eval do ...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文