Why does this link_to fail when looping through formatter tags?

Can someone explain why the following code snippet fails? I don’t understand why the link_to method is unavailable within my template.

<% current_page.data.tags.split(", ").each do |tag| %>
      <%= link_to tag, tag_path(tag) %>
 <% end %>

No method error
undefined method `link’ for nil:NilClass

It’s hard to say from the information given.

Try using a debugger to find out more exactly where the error is triggered.

There are some debugging help in RubyMine Debugging Middleman using RubyMine or Pry Exploring sitemap with pry?

Ended up solving achieving what I wanted a list of posts’ tags linked to the corresponding tag when directory_indexes are on thru Google Fu:

<%= current_page.data.tags.split(", ").collect{|tag| link_to tag, '/tags/'+tag }.join(", ") %>

I wonder if there is a more elegant way to create the link than hard coding the tags directory path, given that directory_indexes may or may not be on.