0
votes

I have an erb block:

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

I want to put different contents inside the content_for block so I tried defacing it like so:

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

This raises an error:

syntax error, unexpected '<', expecting keyword_end

Defacing a ruby block is something I never tried before.. Any ideas?

1

1 Answers

1
votes

The error is because of content_for in -

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

content_for is an helper method in rails which stores a block of markup inside do.....end for later use.

and erb[silent]:contains() selector in deface works on ruby/rails code.

So when you are writing 'content_for :sidebar' inside selector it finds do...end missing and generates error of expecting keyword_end

For example this code will not raise any error -

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

because if @product.sold? is a valid ruby/rails code.