From d44d5bd3789151df1bfda657317d83bdaa433998 Mon Sep 17 00:00:00 2001 From: Stella Date: Sun, 30 Nov 2014 12:47:22 +0200 Subject: [PATCH] do not allow creation of proposal with keynote type --- app/controllers/proposal_controller.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/app/controllers/proposal_controller.rb b/app/controllers/proposal_controller.rb index 5956f24f..a0659071 100644 --- a/app/controllers/proposal_controller.rb +++ b/app/controllers/proposal_controller.rb @@ -39,6 +39,16 @@ class ProposalController < ApplicationController @event.event_users.new(user: current_user, event_role: 'speaker') + type_id = params[:event][:event_type_id].to_f + keynote_ids = EventType.where(title: 'Keynote').pluck(:id) + + if keynote_ids.include? type_id + @event.errors.add(:event_type_id, 'You are not allowed to create a Keynote!') + flash[:error] = "Could not submit proposal: #{@event.errors.full_messages.join(', ')}" + render action: 'new' + return + end + if !@event.save flash[:error] = "Could not submit proposal: #{@event.errors.full_messages.join(', ')}" render action: 'new'