osem-fcy/app/controllers/admin/commercials_controller.rb

59 lines
1.7 KiB
Ruby
Raw Normal View History

2014-08-07 07:42:22 +03:00
module Admin
class CommercialsController < Admin::BaseController
2014-08-12 11:51:59 +03:00
load_and_authorize_resource :conference, find_by: :short_title
load_and_authorize_resource through: :conference, except: [:new, :create]
2014-08-07 07:42:22 +03:00
def index
@commercials = @conference.commercials
end
2014-08-07 07:42:22 +03:00
def new
@commercial = @conference.commercials.build
authorize! :create, @conference.commercials.new
2014-08-07 07:42:22 +03:00
end
def edit; end
2014-08-07 07:42:22 +03:00
def create
@commercial = @conference.commercials.build(commercial_params)
authorize! :create, @commercial
2014-08-07 07:42:22 +03:00
if @commercial.save
2015-10-17 16:57:48 +03:00
flash[:notice] = 'Commercial was successfully created.'
redirect_to admin_conference_commercials_path
2014-08-07 07:42:22 +03:00
else
2014-11-30 15:41:47 +02:00
flash[:error] = "An error prohibited this Commercial from being saved: #{@commercial.errors.full_messages.join('. ')}."
2014-08-07 07:42:22 +03:00
render :new
end
end
2014-08-07 07:42:22 +03:00
def update
if @commercial.update(commercial_params)
2015-10-17 16:57:48 +03:00
flash[:notice] = 'Commercial was successfully updated.'
redirect_to admin_conference_commercials_path
2014-08-07 07:42:22 +03:00
else
2014-11-30 15:41:47 +02:00
flash[:error] = "An error prohibited this Commercial from being saved: #{@commercial.errors.full_messages.join('. ')}."
2014-08-07 07:42:22 +03:00
render :edit
end
end
2014-08-07 07:42:22 +03:00
def destroy
2015-10-17 16:57:48 +03:00
if @commercial.destroy
flash[:notice] = 'Commercial was successfully destroyed.'
redirect_to admin_conference_commercials_path
else
flash[:error] = 'Commercial was not destroyed.'\
"#{@commercial.errors.full_messages.join('. ')}"
redirect_to admin_conference_commercials_path
end
2014-08-07 07:42:22 +03:00
end
2014-08-07 07:42:22 +03:00
private
2014-08-07 07:42:22 +03:00
def commercial_params
#params.require(:commercial).permit(:commercial_id, :commercial_type)
params[:commercial]
end
end
end