我想添加分类从侧边栏到主页,而不是产品清单,但我的污点不起作用。
Deface::Override.new(
:virtual_path => 'spree/shared/_products',
:name => 'change view',
:replace => "[data-hook='homepage_products']",
:text => "
<% max_level = Spree::Config[:max_level_in_taxons_menu] || 1 %>
<nav id='taxonomies2' class='sidebar-item' data-hook>
<% @taxonomies.each do |taxonomy| %>
<% cache [I18n.locale, taxonomy, max_level] do %>
<h4 class='taxonomy-root'><%= Spree.t(:shop_by_taxonomy, :taxonomy => taxonomy.name) %></h4>
<%= taxons_tree(taxonomy.root, @taxon, max_level) %>
<% end %>
<% end %>
</nav> ")我被困得很厉害。
发布于 2015-05-22 09:33:40
您应该用主页索引视图one:spree/home/index替换虚拟路径,在这里放置要替换的元素。
另外,我不确定名字是否应该包含一个空格,尝试用"change_view“来更改它。始终确保名称是唯一的,并在添加新的删除覆盖文件时重新启动服务器。
发布于 2016-03-17 10:54:05
案例-重新启动服务器:无需每次在重写中更改时重新启动服务器。
是的,如果您已经设置了config.deface.enabled = false,您应该这样做;通常我们在production.rb中设置它,在这种情况下,您应该预编译重写。有关更多信息,请参阅此
调试技术:如果不确定部分/模板的路径是否正确,则可以使用此技术进行验证
$ rake deface:get_result['spree/shared/_link_to_account']
=> ActionView::MissingTemplate: Missing template
$ rake deface:get_result['spree/shared/_login_bar']
# ---------------- Before ----------------
# <% if spree_current_user %>
# <li><%= link_to Spree.t(:my_account), spree.account_path %></li>
# <li><%= link_to Spree.t(:logout), spree.logout_path %></li>
# <% else %>您甚至可以验证选择器,例如
$ rake deface:test_selector['spree/shared/_login_bar , li']
# Querying 'spree/shared/_login_bar' for 'li'
# ---------------- Match 1 ----------------
# <li>
# <%= link_to 'Dashboard', '/admin' if spree_current_user.is_admin? %> </li>
# ---------------- Match 2 ----------------此外,即使在验证了选择器之后,如果错误仍然存在,则必须确保要替换的text不包含任何syntax/runtime错误。
https://stackoverflow.com/questions/30372496
复制相似问题