paginate photos

master
Coleman 2008-06-27 20:54:48 -05:00
parent c9218b951d
commit 3dca339ab1
2 changed files with 38 additions and 5 deletions

View File

@ -16,6 +16,16 @@ class Albums < Application
def show def show
@album = Album.find_by_name(params[:id].gsub(/_/, ' ')) @album = Album.find_by_name(params[:id].gsub(/_/, ' '))
raise NotFound unless @album raise NotFound unless @album
pcount = @album.photos.size
@page = params[:page].to_i
per_page = 20
@page_count = (pcount.to_f / per_page.to_f).ceil.to_i
@page = 0 if @page >= @page_count
@url_key = :photos
@photos = @album.photos.find(:all, :limit => per_page, :offset => (@page * per_page), :order => 'filename ASC')
display @album display @album
end end

View File

@ -7,8 +7,33 @@
<% throw_content :for_stylesheet do -%> <% throw_content :for_stylesheet do -%>
.photo { .photo_collection_item {
margin: 10px; word-wrap: break-word;
width: 150px;
min-height: 150px;
max-height: 150px;
margin-top: 15px;
margin-bottom: 15px;
padding: 3px;
border: 1px solid #BBB;
float: left;
position: relative;
}
.col_1 {
margin-left: 5px;
}
.col_2 {
margin-left: 5px;
}
.col_3 {
margin-left: 5px;
}
.col_0 {
margin-left: 5px;
} }
<% end -%> <% end -%>
@ -17,9 +42,7 @@
<h1><%= @album.name -%></h1> <h1><%= @album.name -%></h1>
<% @album.photos.each_with_index do |photo, idx| -%> <% @album.photos.each_with_index do |photo, idx| -%>
<% if (idx + 1) % 3 == 1 -%><p><% end -%> <div class="photo_collection_item col_<%= (idx + 1) % 4 -%>"><a href="<%= url(:photo, photo) -%>" rel="nofollow" onclick="window.open(this.href);return false;"><img src="<%= thumbnail_photo_url(photo) -%>" /></a></div>
<span class="photo"><a href="<%= url(:photo, photo) -%>" rel="nofollow" onclick="window.open(this.href);return false;"><img src="<%= thumbnail_photo_url(photo) -%>" /></a></span>
<% if (idx + 1) % 3 == 0 or @album.photos.size == (idx + 1) -%></p><% end -%>
<% end -%> <% end -%>
<% unless @album.tags.empty? -%> <% unless @album.tags.empty? -%>