This repository has been archived on 2020-05-27. You can view files and clone it, but cannot push or open issues/pull-requests.
binaryattraction/app/controllers/favorites.rb

39 lines
1020 B
Ruby
Raw Normal View History

2008-10-01 02:19:35 -04:00
class Favorites < Application
before :logged_in?
def show
@page = params[:page].to_i
per_page = 24
@page_count = (current_user.photo_favorites.count(:id).to_f / per_page.to_f).ceil
@photos = current_user.favorite_photos.find :all, :order => 'id DESC', :limit => per_page, :offset => (per_page * @page)
if request.xhr?
partial 'photos/photo_browser'
else
render
end
2008-10-01 02:19:35 -04:00
end
def create
raise NotAcceptable unless request.xhr?
@photo = Photo.find params[:photo_id] rescue nil
pf = PhotoFavorite.new :photo_id => @photo.id, :user_id => current_user.id
if pf.save
render '', :status => 200
else
render '', :status => 403
end
end
def destroy
raise NotAcceptable unless request.xhr?
pf = current_user.photo_favorites.detect do |f|
f.photo_id == params[:id].to_i
end
if pf and pf.user_id == current_user.id and pf.destroy
render '', :status => 200
else
render '', :status => 403
end
end
2008-10-01 02:19:35 -04:00
end