[英]Include a custom module on Spree and Rails
I'm trying to add my module to my class_eval
on Spree. 我正在尝试将模块添加到Spree上的
class_eval
中。
This is located on: lib/spree/core/app/models/spree/payment/processing.rb
该文件位于:
lib/spree/core/app/models/spree/payment/processing.rb
Tried with the following: 尝试了以下内容:
module Spree
Payment.class_eval do
require GatewayError
end
end
I am trying to include the following located on: lib/spree/error_override.rb
我试图包括以下内容:
lib/spree/error_override.rb
module Spree
module GatewayError
end
end
The error I'm getting when I try to load the server is: 尝试加载服务器时出现的错误是:
`block in <module:Spree>': uninitialized constant Spree::GatewayError (NameError)
Its my first time trying to include my own module to a class, would be awesome if someone can point me in the right direction. 如果有人可以向正确的方向指出我的想法,那是我第一次尝试将自己的模块包括在课程中。
Thank you in advance! 先感谢您!
One solution would be to manually require the file during initialization process. 一种解决方案是在初始化过程中手动要求文件。
config/initializers/require.rb: 配置/初始化/ require.rb:
# put here all files that you want to require manually
require "#{Rails.root}/lib/spree/error_override.rb"
And that's it - your module is now ready to use ;) 就是这样-您的模块现在可以使用了;)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.