17

これを使用して base_helper.rb のヘルパー メソッドをオーバーライドしようとしています。

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

代わりは。

4

1 に答える 1

23

モジュールを再度開いても同様に機能します。

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

class_evalandを使用する特別な理由はありませんmodule_eval。Spree プロジェクトでは長い間、それが習慣になっているだけです。

于 2012-08-22T14:26:32.213 に答える