Helper Spree覆盖帮助器方法
我正试图使用以下方法覆盖base_helper.rb的helper方法:Helper Spree覆盖帮助器方法,helper,spree,overriding,Helper,Spree,Overriding,我正试图使用以下方法覆盖base_helper.rb的helper方法: module Spree module BaseHelper.class_eval do def taxons_tree(root_taxon, current_taxon, max_level = 1) ..... end end end 这对我不起作用。有人知道我在这里错过了什么吗 谢谢大家! 固定: 我应该使用: Spree::BaseHelper.module_eval d
module Spree
module BaseHelper.class_eval do
def taxons_tree(root_taxon, current_taxon, max_level = 1)
.....
end
end
end
这对我不起作用。有人知道我在这里错过了什么吗
谢谢大家!
固定:
我应该使用:
Spree::BaseHelper.module_eval do
def taxons_tree(root_taxon, current_taxon, max_level = 1)
...
end
end
相反。重新打开模块也同样有效:
module Spree
module BaseHelper
def taxons_tree(root_taxon, current_taxon, max_level = 1)
...
end
end
end
没有特别的理由使用
class\u eval
和module\u eval
,这只是Spree项目中很长一段时间的习惯。Ryan,我们把这些代码放在哪里。我需要重写link\u to\u cart
方法来创建定制的购物车段。我来自PHP,如果这是一个Rails问题,我很抱歉但非常感谢您的评论。在app/helpers下创建一个名为spree的文件夹,并将Ryan Bigg的代码放入一个名为caalled base_helper的文件中。rb@JoaoPereira如果调用base_helper.rb,spree将不会加载原始的base_helper.rb。您必须复制/粘贴每个函数,才能使其正常工作。但是如果你调用base\u helper\u decorator.rb,它就可以工作了。对我来说,它只在使用Spree::BaseHelper.class\u eval时工作