狂欢覆盖帮助方法

lng*_*n55 16 overriding helper spree

我正在尝试使用以下方法覆盖base_helper.rb的辅助方法:

module Spree
  module BaseHelper.class_eval do

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

  end
end
Run Code Online (Sandbox Code Playgroud)

它不适合我.谁知道我在这里失踪了什么?

谢谢!

固定:

我应该用:

Spree::BaseHelper.module_eval do

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

end
Run Code Online (Sandbox Code Playgroud)

代替.

Rya*_*igg 22

重新打开模块也可以正常工作:

module Spree
  module BaseHelper
   def taxons_tree(root_taxon, current_taxon, max_level = 1)
      ...
   end
  end
end
Run Code Online (Sandbox Code Playgroud)

有使用没有特别的理由class_evalmodule_eval,一直只是在施普雷项目的习惯了很长一段时间.

  • @JoaoPereira如果你调用base_helper.rb,spree将不会加载原始的base_helper.rb.您必须复制/粘贴每个功能,才能正常运行.但是如果你调用base_helper_decorator.rb,它就可以了. (14认同)
  • 在app/helpers下创建一个名为spree的文件夹,并将Ryan Bigg中的代码放入一个文件caalled base_helper.rb (3认同)
  • 瑞安,我们把这个代码放在哪里.我需要覆盖`link_to_cart`方法来制作定制的购物车细分市场.我来自PHP,如果这是一个Rails问题,我很抱歉,但非常感谢评论. (2认同)