为什么我的代码没有覆盖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
答案 0 :(得分:1)
您在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
答案 1 :(得分:0)
在上方查找接受的答案
所以在我将装饰器文件添加到初始化程序的要求后,它就起作用了:
spree.rb
require "#{Rails.root}/app/helpers/spree/frontend_helper_decorator.rb"
要添加所有辅助装饰器,请使用以下代码:
Dir["#{Rails.root}/app/helpers/spree/*.rb"].each {|file| require file }
不要忘记在此更改后重新启动服务器!