nuT707
nuT707

Reputation: 1573

Can't override Spree's helper's method

Why my code not overriding Spree's code?

app/helpers/spree/frontend_helper_decorator.rb

Spree::FrontendHelper.module_eval do

    def taxons_tree(root_taxon, current_taxon, max_level = 1)
      return '' if max_level < 1 || root_taxon.children.empty?
      content_tag :ul, class: 'taxons-list' do
        root_taxon.children.map do |taxon|
          css_class = (current_taxon && current_taxon.self_and_ancestors.include?(taxon)) ? 'current' : nil
          content_tag :li, class: css_class do
           link_to(taxon.name, seo_url(taxon)) +
           taxons_tree(taxon, current_taxon, max_level - 1)
          end
        end.join("\n").html_safe
      end
    end

end

Upvotes: 2

Views: 750

Answers (2)

nuT707
nuT707

Reputation: 1573

Look accepted answer above

So it worked after i've added decorator file as require to initilizer:

spree.rb

require "#{Rails.root}/app/helpers/spree/frontend_helper_decorator.rb"

To add all helpers decorator i use this code:

Dir["#{Rails.root}/app/helpers/spree/*.rb"].each {|file| require file }

Don't forget to restart server after this changes!

Upvotes: 2

Did you have this in your application.rb ?

config.to_prepare do
  # Load application's model / class decorators
  Dir.glob(File.join(File.dirname(__FILE__), "../app/**/*_decorator*.rb")) do |c|
    Rails.configuration.cache_classes ? require(c) : load(c)
  end

  # Load application's view overrides
  Dir.glob(File.join(File.dirname(__FILE__), "../app/overrides/*.rb")) do |c|
    Rails.configuration.cache_classes ? require(c) : load(c)
  end
end

Upvotes: 2

Related Questions