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

65 lines
2.1 KiB
Ruby
Raw Normal View History

module Admin
class SponsorshipLevelsController < 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
2014-08-12 11:51:59 +03:00
def index
authorize! :index, SponsorshipLevel.new(conference_id: @conference.id)
end
def edit; end
def new
@sponsorship_level = @conference.sponsorship_levels.new
end
def create
@sponsorship_level = @conference.sponsorship_levels.new(sponsorship_level_params)
if @sponsorship_level.save
2015-10-17 16:57:48 +03:00
flash[:notice] = 'Sponsorship level successfully created.'
redirect_to admin_conference_sponsorship_levels_path(conference_id: @conference.short_title)
else
flash[:error] = "Creating Sponsorship Level failed: #{@sponsorship_level.errors.full_messages.join('. ')}."
render :new
end
end
def update
if @sponsorship_level.update_attributes(sponsorship_level_params)
2015-10-17 16:57:48 +03:00
flash[:notice] = 'Sponsorship level successfully updated.'
redirect_to admin_conference_sponsorship_levels_path(conference_id: @conference.short_title)
else
flash[:error] = "Update Sponsorship level failed: #{@sponsorship_level.errors.full_messages.join('. ')}."
render :edit
end
end
def destroy
if @sponsorship_level.destroy
2015-10-17 16:57:48 +03:00
flash[:notice] = 'Sponsorship level successfully deleted.'
redirect_to admin_conference_sponsorship_levels_path(conference_id: @conference.short_title)
else
2015-10-17 16:57:48 +03:00
flash[:error] = 'Deleting sponsorship level failed! ' \
"#{@sponsorship_level.errors.full_messages.join('. ')}."
redirect_to admin_conference_sponsorship_levels_path(conference_id: @conference.short_title)
end
end
def up
@sponsorship_level.move_higher
2015-10-17 16:57:48 +03:00
redirect_to admin_conference_sponsorship_levels_path(conference_id: @conference.short_title)
end
def down
@sponsorship_level.move_lower
2015-10-17 16:57:48 +03:00
redirect_to admin_conference_sponsorship_levels_path(conference_id: @conference.short_title)
end
private
def sponsorship_level_params
params[:sponsorship_level]
end
end
end