Permit to modify contestants categories
This commit is contained in:
@@ -24,6 +24,7 @@ class ContestantsController < ApplicationController
|
||||
@contestant = Contestant.new(contestant_params)
|
||||
@contestant.contest_id = @contest.id
|
||||
if @contestant.save
|
||||
update_contestant_categories
|
||||
redirect_to contest_path(@contest), notice: t("contestants.new.notice")
|
||||
else
|
||||
@action_name = t("helpers.buttons.back")
|
||||
@@ -36,6 +37,7 @@ class ContestantsController < ApplicationController
|
||||
authorize @contest
|
||||
|
||||
if @contestant.update(contestant_params)
|
||||
update_contestant_categories
|
||||
redirect_to @contest, notice: t("contestants.edit.notice")
|
||||
else
|
||||
@action_name = t("helpers.buttons.back")
|
||||
@@ -126,4 +128,15 @@ class ContestantsController < ApplicationController
|
||||
def contestant_params
|
||||
params.expect(contestant: [ :email, :name ])
|
||||
end
|
||||
|
||||
def update_contestant_categories
|
||||
@contestant.categories.clear
|
||||
@contest.categories.each do |category|
|
||||
logger.info(params[:contestant]["category_#{category.id}".to_sym] == "1")
|
||||
if params[:contestant].key?("category_#{category.id}".to_sym) && params[:contestant]["category_#{category.id}".to_sym] == "1"
|
||||
@contestant.categories << category
|
||||
end
|
||||
end
|
||||
@contestant.save
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user