ruby on rails - Sorting and grouping array, hash with all items appears at the end -
i have table leaflets data sorted date in controller:
@leaflets = leaflet.order(:date)
and grouped dates in view (i found code somewhere on internet)
<%= @leaflets.group_by(&:date).each |date, leaflets| %> <p><%= l(date, :format => '%a, %d %b %y') %></p> <!-- localized date formatting: weekday, day month year --> <table> <tr> <% leaflets.each |leaflet| %> <td style="border:dotted 1px; padding:5px;"> <strong><%= leaflet.place %></strong><br/> <%= leaflet.description %><br/> <%= link_to "zapisz siÄ™", leaflet_path(leaflet) %> </td> </a> <% end %> </tr> </table> <% end %>
everything works great, prints items hash @ end:
{tue, 11 nov 2014=>[#<leaflet id: 14, date: "2014-11-11", place: "miejsce11-11-a", description: nil, program: nil, modifier: nil, created_at: "2014-12-05 21:58:01", updated_at: "2014-12-05 21:58:01">, #<leaflet id: 15, date: "2014-11-11", place: "miejsce11-11-b", description: nil, program: nil, modifier: nil, created_at: "2014-12-05 21:58:04", updated_at: "2014-12-05 21:58:04">, #<leaflet id: 16, date: "2014-11-11", place: "miejsce11-11-c", description: nil, program: nil, modifier: nil, created_at: "2014-12-05 21:58:07", updated_at: "2014-12-05 21:58:07">], mon, 01 dec 2014=>[#<leaflet id: 4, date: "2014-12-01", place: "miejsce1", description: nil, program: nil, modifier: nil, created_at: "2014-12-05 21:56:42", updated_at: "2014-12-05 21:56:42">, #<leaflet id: 5, date: "2014-12-01", place: "miejsce2", description: nil, program: nil, modifier: nil, created_at: "2014-12-05 21:56:55", updated_at: "2014-12-05 21:56:55">, #<leaflet id: 6, date: "2014-12-01", place: "miejsce3", description: nil, program: nil, modifier: nil, created_at: "2014-12-05 21:57:01", updated_at: "2014-12-05 21:57:01">], tue, 02 dec 2014=>[#<leaflet id: 7, date: "2014-12-02", place: "miejsce02-a", description: nil, program: nil, modifier: nil, created_at: "2014-12-05 21:57:21", updated_at: "2014-12-05 21:57:21">, #<leaflet id: 8, date: "2014-12-02", place: "miejsce02-b", description: nil, program: nil, modifier: nil, created_at: "2014-12-05 21:57:24", updated_at: "2014-12-05 21:57:24">, #<leaflet id: 9, date: "2014-12-02", place: "miejsce02-c", description: nil, program: nil, modifier: nil, created_at: "2014-12-05 21:57:28", updated_at: "2014-12-05 21:57:28">], fri, 05 dec 2014=>[#<leaflet id: 10, date: "2014-12-05", place: "miejsce05-a", description: nil, program: nil, modifier: nil, created_at: "2014-12-05 21:57:40", updated_at: "2014-12-05 21:57:40">, #<leaflet id: 11, date: "2014-12-05", place: "miejsce05-b", description: nil, program: nil, modifier: nil, created_at: "2014-12-05 21:57:43", updated_at: "2014-12-05 21:57:43">, #<leaflet id: 12, date: "2014-12-05", place: "miejsce05-c", description: nil, program: nil, modifier: nil, created_at: "2014-12-05 21:57:46", updated_at: "2014-12-05 21:57:46">, #<leaflet id: 13, date: "2014-12-05", place: "miejsce05-d", description: nil, program: nil, modifier: nil, created_at: "2014-12-05 21:57:48", updated_at: "2014-12-05 21:57:48">]}
any idea what's wrong? normal behaviour grouping in rails? how can delete big hash? screenshot: http://imgur.com/nc9sys7
just remove =
from:
<%= @leaflets.group_by(&:date).each |date, leaflets| %>
so reads:
<% @leaflets.group_by(&:date).each |date, leaflets| %>
the =
outputing results of each
call.
Comments
Post a Comment