Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spree overriding helper method

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.

like image 411
lnguyen55 Avatar asked Aug 16 '12 13:08

lnguyen55


1 Answers

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.

like image 109
Ryan Bigg Avatar answered Sep 21 '22 15:09

Ryan Bigg