38 lines
895 B
Ruby
38 lines
895 B
Ruby
class CategoriesController < ApplicationController
|
|
before_action :set_contest
|
|
before_action :set_category, only: %i[ destroy]
|
|
|
|
def create
|
|
authorize @contest
|
|
|
|
@category = Category.new(category_params)
|
|
@category.contest_id = @contest.id
|
|
if @category.save
|
|
redirect_to "/contests/#{@contest.id}/settings/categories", notice: t("categories.new.notice")
|
|
else
|
|
redirect_to "/contests/#{@contest.id}/settings/categories", notice: t("categories.new.error")
|
|
end
|
|
end
|
|
|
|
def destroy
|
|
authorize @contest
|
|
|
|
@category.destroy
|
|
redirect_to "/contests/#{@contest.id}/settings/categories", notice: t("categories.destroy.notice")
|
|
end
|
|
|
|
private
|
|
|
|
def set_contest
|
|
@contest = Contest.find(params[:contest_id])
|
|
end
|
|
|
|
def set_category
|
|
@category = Category.find(params[:id])
|
|
end
|
|
|
|
def category_params
|
|
params.expect(category: [ :name ])
|
|
end
|
|
end
|