Note that there are some explanatory texts on larger screens.

plurals
  1. PORails link_to do block gives `unexpected keyword_do_block` error
    primarykey
    data
    text
    <p>I'm trying to use a <code>link_to</code> block in Rails 2.3.14 with Ruby 1.9.3, and it's causing <code>ActionView::TemplateError syntax error, unexpected keyword_do_block</code></p> <p><strong>HTML</strong></p> <pre><code>&lt;% @contents.each do |item| %&gt; &lt;%= link_to "#" do %&gt; # this is the line referenced in the error message &lt;%= content_tag(:h3, item.title) %&gt; &lt;div class="details"&gt; # divs with text &lt;/div&gt; &lt;% end %&gt; &lt;% end %&gt; </code></pre> <p><strong>Detailed error message</strong></p> <p>The lines of code included in the error message do not perfectly match the code included above, which I simplified for debugging, but you can see that the line referenced is the same.</p> <pre><code>ActionView::TemplateError (/my/file/_partial.html.erb:78: syntax error, unexpected keyword_do_block ...;@output_buffer.safe_concat((do).to_s);@output_buffer.safe_c... ... ^ /my/file/_partial.html.erb:97: syntax error, unexpected keyword_else, expecting keyword_end '); else ^ /my/file/_partial.html.erb:123: syntax error, unexpected keyword_ensure, expecting $end) on line #78 of app/views/content/_list.html.erb: 75: &lt;%= hoverhide_image(item) %&gt; 76: &lt;/div&gt; 77: &lt;div class="hovershow"&gt; 78: &lt;%= link_to("#") do %&gt; 79: &lt;%= content_tag(:h3, item.title) %&gt; 80: &lt;div class="details"&gt; 81: &lt;div&gt; </code></pre> <p>If I replace the <code>link_to</code> block with <code>a</code> tags, it renders perfectly. </p> <p>If I remove the <code>=</code> from line 3 (making it <code>&lt;% link_to "#" do %&gt;</code> instead), no error is thrown, but of course my text doesn't render.</p> <p>Any idea what's going on?</p> <p>(edited to add more details on the error message)</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload