修改订单模型时出现问题:未初始化常量 Order (NameError) - Spree 0.60.1
这是我在列表中的第一篇文章,但在我寻求帮助之前,我要感谢你们所有人创建的精彩平台。
在我正在从事的一个项目中,需要捐赠/捐赠功能。我已按照自定义指南 (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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
谢谢布莱恩 (https://groups.google.com/forum/ #!topic/spree-user/mGcj4EpGuYo/discussion) 进行修复。在 spree 中,添加所有以 '_decorator' 结尾的文件所需的 require 语句需要进入 'self.activate' 块内部:
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:
这破坏了 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 ...