Display sponsor pages only if sponsorship levels are defined

This commit is contained in:
Nishanth Vijayan 2016-05-16 01:08:06 +05:30
parent 02487be6fb
commit e83b2c3a90
2 changed files with 8 additions and 1 deletions

View file

@ -2,6 +2,7 @@ module Admin
class SponsorsController < Admin::BaseController
load_and_authorize_resource :conference, find_by: :short_title
load_and_authorize_resource :sponsor, through: :conference
before_action :sponsorship_level_required, only: [:index, :new]
def index
authorize! :index, Sponsor.new(conference_id: @conference.id)
@ -51,5 +52,11 @@ module Admin
def sponsor_params
params.require(:sponsor).permit(:name, :description, :website_url, :picture, :picture_cache, :sponsorship_level_id, :conference_id)
end
def sponsorship_level_required
return unless @conference.sponsorship_levels.empty?
redirect_to admin_conference_sponsorship_levels_path(conference_id: @conference.short_title),
alert: 'You need to create atleast one sponsorship level to add a sponsor'
end
end
end