疯狂覆写辅助方法 [英] Spree overriding helper method
本文介绍了疯狂覆写辅助方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用以下方法覆盖base_helper.rb的帮助方法:
I'm trying to overriding a helper method of base_helper.rb by using this:
module Spree
module BaseHelper.class_eval do
def taxons_tree(root_taxon, current_taxon, max_level = 1)
.....
end
end
end
对我不起作用.有人知道我在这里想念什么吗?
It's not working for me. Anyone know what I am missing here?
谢谢!
已修复:
我应该使用:
Spree::BaseHelper.module_eval do
def taxons_tree(root_taxon, current_taxon, max_level = 1)
...
end
end
相反.
推荐答案
重新打开该模块同样适用:
Re-opening the module will work just as well:
module Spree
module BaseHelper
def taxons_tree(root_taxon, current_taxon, max_level = 1)
...
end
end
end
使用class_eval
和module_eval
并没有特别的原因,这在Spree项目中已经很长时间了.
There's no particular reason to use class_eval
and module_eval
, it's just been the habit in the Spree project for a very long time.
这篇关于疯狂覆写辅助方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文