【问题标题】:Spree with deface - Use deface to replace contents of blockSpree with deface - 使用 deface 替换块的内容
【发布时间】:2014-12-30 16:22:42
【问题描述】:

我有一个 erb 块:

 <% content_for :sidebar do %>
 <% if defined? @products && defined? @taxon %>
   <%= render :partial => "spree/shared/filters" %>
     <% elsif defined? @taxonomies %>
   <%= render :partial => "spree/shared/taxonomies" %>
     <% end %>
 <% end %>

我想在 content_for 块中放入不同的内容,所以我尝试像这样破坏它:

<!-- replace_contents "erb[silent]:contains('content_for :sidebar')" -->
<%= render partial: "test" %>

这会引发错误:

语法错误,意外的'

破坏红宝石块是我以前从未尝试过的事情。有什么想法吗?

【问题讨论】:

    标签: ruby-on-rails spree deface


    【解决方案1】:

    错误是因为content_for in -

    <!-- replace_contents "erb[silent]:contains('content_for :sidebar')" -->
    

    content_for 是 rails 中的一个辅助方法,它将标记块存储在 do.....end 中以供以后使用。

    erb[silent]:contains() deface 中的选择器适用于 ruby​​/rails 代码。

    因此,当您在选择器中写入'content_for :sidebar' 时,它会发现do...end 丢失并生成expecting keyword_end 错误

    例如此代码不会引发任何错误 -

    <!-- replace_contents "erb[silent]:contains('if @product.sold?')" -->
    

    因为if @product.sold? 是有效的 ruby​​/rails 代码。

    【讨论】:

    • 谢谢!我就是这么做的。我最终得到了以下代码:
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-02-04
    • 1970-01-01
    • 1970-01-01
    • 2013-07-21
    • 2013-07-31
    • 2017-04-18
    • 1970-01-01
    相关资源
    最近更新 更多