Refactor admin/call_for_booth controller

This commit is contained in:
nasia 2017-06-10 23:50:31 +03:00
parent 6a8b9f8d2d
commit a5ce1239f2
17 changed files with 182 additions and 18 deletions

View file

@ -0,0 +1,21 @@
module Admin
class Admin::BoothsController < Admin::BaseController
load_and_authorize_resource :conference, find_by: :short_title
load_and_authorize_resource :booth, through: :conference
def index
@booths = @conference.booths
end
def show; end
def new; end
def create; end
def update; end
def destroy; end
end
end

View file

@ -0,0 +1,55 @@
module Admin
class CallForBoothsController < Admin::BaseController
load_and_authorize_resource :conference, find_by: :short_title
load_and_authorize_resource through: :conference, singleton: true
def show; end
def new
@call_for_booth = CallForBooth.new(conference: @conference)
end
def edit; end
def create
@call_for_booth = @conference.call_for_booth.build(call_for_booth_params)
if @call_for_booth.save
redirect_to admin_conference_call_for_booth_path,
notice: "Call for booths successfully created."
else
flash[:error] = "Creating the call for booths failed. #{@call_for_booth.errors.full_messages.join('. ')}."
render :new
end
end
def update
@call_for_booth = @conference.call_for_booth
@call_for_booth.assign_attributes(call_for_booth_params)
if @call_for_booth.update_attributes(call_for_booth_params)
redirect_to admin_conference_call_for_booth_path(@conference.short_title),
notice: 'Call for booths successfully updated.'
else
flash.now[:error] = "Updating call for booths failed. #{@call_for_booth.errors.to_a.join('. ')}."
render :new
end
end
def destroy
if @call_for_booth.destroy
redirect_to admin_conference_call_for_booth_path, notice: 'Call for Booths successfully deleted.'
else
redirect_to admin_conference_call_for_booth_path, error: 'An error prohibited this Call for Booths from being destroyed: '\
"#{@call_for_booth.errors.full_messages.join('. ')}."
end
end
private
def call_for_booth_params
params.require(:call_for_booth).permit(:start_date, :end_date, :booth_limit)
end
end
end

View file

@ -2,22 +2,18 @@ class BoothsController < ApplicationController
before_action :set_booth, only: [:show, :edit, :update, :destroy]
# GET /booths
# GET /booths.json
def index
@booths = Booth.all
respond_to do |format|
format.html # index.html.erb
format.json { render json: @booths }
end
end
# GET /booths/1
# GET /booths/1.json
def show
respond_to do |format|
format.html # show.html.erb
format.json { render json: @booth }
end
end
@ -31,42 +27,34 @@ class BoothsController < ApplicationController
end
# POST /booths
# POST /booths.json
def create
@booth = Booth.new(booth_params)
respond_to do |format|
if @booth.save
format.html { redirect_to @booth, notice: 'Booth was successfully created.' }
format.json { render json: @booth, status: :created }
else
format.html { render action: 'new' }
format.json { render json: @booth.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /booths/1
# PATCH/PUT /booths/1.json
def update
respond_to do |format|
if @booth.update(booth_params)
format.html { redirect_to @booth, notice: 'Booth was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: 'edit' }
format.json { render json: @booth.errors, status: :unprocessable_entity }
end
end
end
# DELETE /booths/1
# DELETE /booths/1.json
def destroy
@booth.destroy
respond_to do |format|
format.html { redirect_to booths_url }
format.json { head :no_content }
end
end