rails - when using Group_by - How to get an Index?

Posted by AnApprentice on Stack Overflow See other posts from Stack Overflow or by AnApprentice
Published on 2011-02-12T22:23:42Z Indexed on 2012/09/25 21:37 UTC
Read the original article Hit count: 276

I have the following:

sets = DataSet.all.group_by{ |data| [data.project_id, "-", data.thread_id].join(" ") }

<% sets.each do |range, datas| %>
  <p><%= range %>:</p>
  <% datas.each do |data| %>
     <%=data%>
    <p>Last Post<%= data.last.created_at %></p>
  <% end %>
<% end %>

Problem is that I need an index. So i updated the above with:

<% sets.each_with_index do |range, datas, i| %>
  <p><%= range %>:</p>
  <% datas.each do |data| %>
     <%= i %>
     <%=data%>
    <p>Last Post<%= data.last.created_at %></p>
  <% end %>
<% end %>

That then breaks, with the error: undefined method `last' for 0:Fixnum

Ideas? thank you

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about ruby