Search code examples
syntaxerblink-tomiddlemanmiddleman-4

Middleman shows syntax error when using a link_to block


I'm using Middleman 4.2 with Middleman-blog 4.0.2.

When I have:

<% blog.tags.each do |tag, articles| %>
   <%= link_to "#{tag.titleize} - #{articles.size}", tag_path(tag) %>
<% end %>

I get the desired <a> element output:

<a href="/blog/posts/tags/test-tag/">Test Tag - 1</a>

But when I change the link_to to a block:

<% blog.tags.each do |tag, articles| %>
   <%= link_to tag_path(tag) do %>
      <%= tag.titleize %> - <%= articles.size %>
   <% end %>
<% end %>

I get a syntax error:

/source/blog/index.html.erb:43: syntax error, unexpected ')' ...<< ( link_to tag_path(tag) do ).to_s; @_out_buf << '

I can't seem to figure out why I'm not able to get the same output here.

Any pointers?


Solution

  • I just realized I had the wrong erb tag on the line with the link_to helper.

    The correct code looks like this:

    <% blog.tags.each do |tag, articles| %>
       <% link_to tag_path(tag) do %>
          <%= tag.titleize %> - <%= articles.size %>
       <% end %>
    <% end %>