2018-05-07 16:47:29 -07:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
2017-02-06 16:11:22 +05:30
|
|
|
module Admin
|
2017-04-04 21:30:16 +03:00
|
|
|
class ResourcesController < Admin::BaseController
|
2017-02-06 16:11:22 +05:30
|
|
|
load_and_authorize_resource :conference, find_by: :short_title
|
|
|
|
|
load_and_authorize_resource :resource, only: [:show, :edit, :update, :destroy]
|
|
|
|
|
|
|
|
|
|
def index; end
|
|
|
|
|
|
|
|
|
|
def edit; end
|
|
|
|
|
|
|
|
|
|
def new
|
|
|
|
|
@resource = @conference.resources.new
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def create
|
|
|
|
|
@resource = @conference.resources.new(resource_params)
|
|
|
|
|
if @resource.save
|
|
|
|
|
redirect_to admin_conference_resources_path(conference_id: @conference.short_title),
|
|
|
|
|
notice: 'Resource successfully created.'
|
|
|
|
|
else
|
2017-04-03 18:34:37 +03:00
|
|
|
flash.now[:error] = "Creating resource failed: #{@resource.errors.full_messages.join('. ')}."
|
2017-02-06 16:11:22 +05:30
|
|
|
render :new
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def update
|
2022-02-14 17:53:58 +01:00
|
|
|
if @resource.update(resource_params)
|
2017-02-06 16:11:22 +05:30
|
|
|
redirect_to admin_conference_resources_path(conference_id: @conference.short_title),
|
|
|
|
|
notice: 'Resource successfully updated.'
|
|
|
|
|
else
|
2017-04-03 18:34:37 +03:00
|
|
|
flash.now[:error] = "Resource update failed: #{@resource.errors.full_messages.join('. ')}."
|
2017-02-06 16:11:22 +05:30
|
|
|
render :edit
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
|
if @resource.destroy
|
|
|
|
|
redirect_to admin_conference_resources_path(conference_id: @conference.short_title),
|
|
|
|
|
notice: 'Resource successfully destroyed.'
|
|
|
|
|
else
|
|
|
|
|
redirect_to admin_conference_resources_path(conference_id: @conference.short_title),
|
|
|
|
|
error: 'Resource was successfully destroyed.' \
|
|
|
|
|
"#{@resource.errors.full_messages.join('. ')}."
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
|
|
def resource_params
|
|
|
|
|
params.require(:resource).permit(:name, :description, :quantity, :used, :conference_id)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|