Created
June 10, 2015 11:43
-
-
Save kelso/36e41a7eaa7e3eeb25bd to your computer and use it in GitHub Desktop.
Groupovanie podla rokov
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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 | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<% @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