【问题标题】:Deface _products data-hook污损 _products 数据挂钩
【发布时间】:2015-05-21 11:31:43
【问题描述】:

我想将侧边栏的分类法添加到主页,而不是产品列表,但我的 deface 不起作用。

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> ")

我被困在这件事上真的很糟糕。

【问题讨论】:

  • nav id标签中不需要提及data-hook,而是在实际视图中提及。

标签: ruby-on-rails spree deface


【解决方案1】:

您应该将虚拟路径替换为主页索引视图之一:spree/home/index,您尝试替换的元素所在的位置。

另外,我不确定名称是否应该包含空格,请尝试使用“change_view”进行更改。始终确保名称是唯一的,并在添加新的污损覆盖文件时重新启动服务器。

【讨论】:

  • 如果是开发环境,添加新的deface override文件时无需重启。
【解决方案2】:

案例 - 重新启动服务器:每次更改覆盖时都无需重新启动服务器。

是的,如果你设置了config.deface.enabled = false,你应该这样做;通常我们在production.rb 中设置它,在这种情况下你应该预编译覆盖。 See this for more info


调试技术: 如果您不确定部分/模板的路径是否正确,则可以使用此技术进行验证

$ 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 错误。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-08-13
    • 1970-01-01
    • 2020-05-02
    • 1970-01-01
    • 2013-01-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多