Skip to content

Instantly share code, notes, and snippets.

@kelso
Created June 10, 2015 11:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kelso/36e41a7eaa7e3eeb25bd to your computer and use it in GitHub Desktop.
Save kelso/36e41a7eaa7e3eeb25bd to your computer and use it in GitHub Desktop.
Groupovanie podla rokov
@albums = Album.all(:conditions => ['published = ?', true], :order => 'created_at desc')
@albums_years = @albums.group_by { |a| a.created_at.beginning_of_year }
# group_by je tu klucovy, vsimni si ze sablona index potom pouziva tu premennu @albums_years
# Tie :conditions je samozrejme zastarala syntax,
# ale aj tak tebe bude stacit Album.all, resp Album.page(...) v pripade strankovania cez kaminari
<% @page_title = 'Fotogaléria' %>
<% @albums_years.each do |year, albums| %>
<h3><%= year.strftime("%Y") %></h3>
<table width="100%" border="0">
<% for album in albums %>
<tr>
<td style="width: 145px; text-align: right; padding-right: 10px; padding-bottom: 10px;">
<% for thumb in album.photos.all(:limit => 3) %>
<%= image_tag(thumb.photo.url(:tiny_square), :style => "border: 1px solid gray; padding: 1px;") %>
<% end %>
</td>
<td style='font-size: 16px; padding-bottom: 10px;'>
<%= link_to album.name, album %>
</td>
<td style="width: 130px; text-align: right;">
<%= album.created_at.strftime("%d.%m.%Y") %>
</td>
</tr>
<% end %>
</table>
<br />
<% end %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment