为什么我的代码没有覆盖 Spree 的代码?
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
最佳答案
您的 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
关于ruby-on-rails - 无法覆盖 Spree 的 helper 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55703865/