Extracting Photos form Conference edit form

close #384
This commit is contained in:
Chrisbr 2014-08-12 08:38:51 +02:00
parent a8b94c13f3
commit 22cc5e4f14
12 changed files with 190 additions and 13 deletions

View file

@ -0,0 +1,65 @@
module Admin
class PhotosController < ApplicationController
before_action :set_conference
before_action :set_photo, only: [:edit, :update, :destroy]
# GET /admin/photos
def index
@photos = @conference.photos.all
end
# GET /admin/photos/new
def new
@photo = @conference.photos.build
end
# GET /admin/photos/1/edit
def edit
end
# POST /admin/photos
def create
@photo = @conference.photos.build(photo_params)
if @photo.save
redirect_to admin_conference_photos_path, notice: 'Photo was successfully created.'
else
flash[:alert] = "A error prohibited this Photo from being saved: #{@photo.errors.full_messages.join('. ')}."
render :new
end
end
# PATCH/PUT /admin/photos/1
def update
if @photo.update(photo_params)
redirect_to admin_conference_photos_path, notice: 'Photo was successfully updated.'
else
flash[:alert] = "A error prohibited this Photo from being saved: #{@photo.errors.full_messages.join('. ')}."
render :edit
end
end
# DELETE /admin/photos/1
def destroy
@photo.destroy
redirect_to admin_conference_photos_path, notice: 'Photo was successfully destroyed.'
end
private
# Use callbacks to share common setup or constraints between actions.
def set_conference
@conference = Conference.find_by(short_title: params[:conference_id])
end
# Use callbacks to share common setup or constraints between actions.
def set_photo
@photo = Photo.find_by(id: params[:id])
end
# Only allow a trusted parameter "white list" through.
def photo_params
params[:photo]
end
end
end