Iterating articles for a Tag and having a counter

Hi there,

i am in the middle of some customizations for a blog i want to put up. I simply want to list the first 4 Articles per Tag and do some templating stuff but even with good java knowledge, i cant get the ERB stuff to go. Here is what i have:

<% blog.tags.each do |tag, articles| %>
  <div id="<%= tag %>" class="tabcontent active">
       <div class="row">
   <% articles[0...4].each do |article| %>
	<div class="col-lg-3 col-md-6 col-sm-12 col-xs-12">
           ...
     <% end %>
    </div>
 </div>
<% end %>

This works ok. Now the thing… i want to have the active class only for the first item in the loop. This is such a basic question, i hardly can type it :wink: I tried the following:

blog.tags.each_with_index do |tag, articles, index| --> doesnt work
I tried only iterating on tags.each_with_index and do an inner loop with tag.articles ----> doesnt work
I tried a manual counter —> seems manually increasing vars in ERB is not possible ?!?

Most likely this is an noob ruby question but even with some time spent on google, i couldnt figure it out. Thanks for help.

Got it. Some more digging deep in Google revealed the following:

<% blog.tags.each_with_index do |(tag, articles), index| %>

So basically just using paranthesis does the work here. Perhaps some other Ruby newbie can learn from it when trying to get some things running with Middleman.