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

33 lines
1.4 KiB
Ruby
Raw Normal View History

2014-08-06 21:14:00 +03:00
module Admin
class DifficultyLevelsController < Admin::BaseController
2014-08-12 11:51:59 +03:00
load_and_authorize_resource :conference, find_by: :short_title
authorize_resource through: :conference
2014-08-06 21:14:00 +03:00
def index
2014-08-12 11:51:59 +03:00
authorize! :index, DifficultyLevel.new(conference_id: @conference.id)
2014-08-06 21:14:00 +03:00
end
2014-02-23 16:09:09 +02:00
2014-08-06 21:14:00 +03:00
def update
if @conference.update_attributes(params[:conference])
if !(@conference.difficulty_levels.count > 0) && @conference.use_difficulty_levels == true
begin
@conference.use_difficulty_levels = false
@conference.save!
flash[:error] = 'You cannot enable the usage of difficulty levels without having set any levels.'
2014-08-12 15:53:50 +03:00
redirect_to(admin_conference_difficulty_levels_path(conference_id: @conference.short_title))
2014-08-06 21:14:00 +03:00
rescue ActiveRecord::RecordInvalid
flash[:error] = 'Something went wrong. Difficulty Levels update failed.'
2014-08-12 15:53:50 +03:00
redirect_to(admin_conference_difficulty_levels_path(conference_id: @conference.short_title))
2014-08-06 21:14:00 +03:00
end
else
flash[:notice] = 'Difficulty Levels were successfully updated.'
2014-08-12 15:53:50 +03:00
redirect_to(admin_conference_difficulty_levels_path(conference_id: @conference.short_title))
2014-02-23 16:09:09 +02:00
end
else
flash[:error] = 'Difficulty Levels update failed.'
2014-08-12 15:53:50 +03:00
redirect_to(admin_conference_difficulty_levels_path(conference_id: @conference.short_title))
2014-02-23 16:09:09 +02:00
end
end
end
2014-06-30 17:07:53 +02:00
end