diff --git a/app/controllers/admin/sponsors_controller.rb b/app/controllers/admin/sponsors_controller.rb index 2ee51762..1c212236 100644 --- a/app/controllers/admin/sponsors_controller.rb +++ b/app/controllers/admin/sponsors_controller.rb @@ -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 diff --git a/app/views/layouts/_admin_sidebar.html.haml b/app/views/layouts/_admin_sidebar.html.haml index 770ba40d..e5747bdc 100644 --- a/app/views/layouts/_admin_sidebar.html.haml +++ b/app/views/layouts/_admin_sidebar.html.haml @@ -107,7 +107,7 @@ - if can? :update, @conference.sponsorship_levels.build %li{:class=> "#{active_nav_li(admin_conference_sponsorship_levels_path(@conference.short_title))}" } = link_to 'Sponsorship Levels', admin_conference_sponsorship_levels_path(@conference.short_title) - - if can? :update, @conference.sponsors.build + - if !@conference.sponsorship_levels.empty? && @conference.sponsorship_levels.first.persisted? && (can? :update, @conference.sponsors.build) %li{:class=> active_nav_li(admin_conference_sponsors_path(@conference.short_title))} = link_to 'Sponsors', admin_conference_sponsors_path(@conference.short_title) - if can? :update, @conference.tickets.build