mirror of
https://github.com/danbee/danbarberphoto
synced 2025-03-04 08:49:07 +00:00
56 lines
1.1 KiB
Ruby
56 lines
1.1 KiB
Ruby
module Admin
|
|
class PhotosController < Admin::AdminController
|
|
before_filter :categories
|
|
|
|
def index
|
|
@photos = Photo.paginate(page: params[:page], per_page: 16)
|
|
end
|
|
|
|
def new
|
|
@photo = Photo.new
|
|
end
|
|
|
|
def edit
|
|
@photo = Photo.find(params[:id])
|
|
end
|
|
|
|
def update
|
|
@photo = Photo.find(params[:id])
|
|
|
|
if @photo.update_attributes(permitted_params)
|
|
redirect_to admin_photos_path, notice: 'Photo was successfully updated.'
|
|
else
|
|
render :edit
|
|
end
|
|
end
|
|
|
|
def create
|
|
@photo = Photo.new(permitted_params)
|
|
|
|
if @photo.save
|
|
redirect_to admin_photos_path, notice: 'Photo was successfully added.'
|
|
else
|
|
render :edit
|
|
end
|
|
end
|
|
|
|
def destroy
|
|
@photo = Photo.find(params[:id])
|
|
@photo.destroy
|
|
|
|
redirect_to :back, notice: 'Photo was deleted.'
|
|
end
|
|
|
|
private
|
|
|
|
def categories
|
|
@categories = Category.all
|
|
end
|
|
|
|
def permitted_params
|
|
params.require(:photo).permit(:image, :title, :description, :flickr_url, :featured,
|
|
:enabled, :taken_at, category_ids: [])
|
|
end
|
|
end
|
|
end
|