Spree overriding helper method

你说的曾经没有我的故事 提交于 2019-12-04 10:10:33

问题


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?

Thank you!

Fixed:

I should use:

Spree::BaseHelper.module_eval do

    def taxons_tree(root_taxon, current_taxon, max_level = 1)
      ...
    end

end

instead.


回答1:


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

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.



来源:https://stackoverflow.com/questions/11988289/spree-overriding-helper-method

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!