1
0
mirror of https://github.com/danbee/danbarberphoto synced 2025-03-04 08:49:07 +00:00
danbarberphoto/app/controllers/photos_controller.rb
Dan Barber e2c4ebf0e9 Use Kaminari instead of WillPaginate
This is to avoid any conflict with Kaminari in Administrate. We also add
some specs for pagination in the front end.
2015-10-26 14:26:32 +00:00

41 lines
783 B
Ruby

class PhotosController < ApplicationController
def index
if params[:category_id]
for_category(params[:category_id])
else
all
end
@num_blank = 11 - @photos.length
respond_to do |format|
format.html
end
end
def log_view
photo = Photo.find_by_id(params[:id])
if photo.present?
photo.log_view
head :ok
else
head :not_found
end
end
private
def for_category(category_id)
@category = Category.find_by_id(category_id)
@photos = @category.photos.enabled.order { taken_at.desc }
.page(params[:page])
@page_title = @category.name
end
def all
@photos = Photo.enabled.order { taken_at.desc }
.page(params[:page])
@page_title = 'All Photos'
end
end