Add contestants
This commit is contained in:
51
app/controllers/contestants_controller.rb
Normal file
51
app/controllers/contestants_controller.rb
Normal file
@@ -0,0 +1,51 @@
|
||||
class ContestantsController < ApplicationController
|
||||
before_action :set_contest
|
||||
before_action :set_contestant, only: %i[ destroy edit update]
|
||||
|
||||
def edit
|
||||
@title = "Edit contestant"
|
||||
end
|
||||
|
||||
def new
|
||||
@contestant = Contestant.new
|
||||
@title = "New contestant"
|
||||
end
|
||||
|
||||
def create
|
||||
@contestant = Contestant.new(contestant_params)
|
||||
@contestant.contest_id = @contest.id
|
||||
if @contestant.save
|
||||
redirect_to contest_path(@contest)
|
||||
else
|
||||
@title = "New contestant"
|
||||
render :new, status: :unprocessable_entity
|
||||
end
|
||||
end
|
||||
|
||||
def update
|
||||
if @contestant.update(contestant_params)
|
||||
redirect_to @contest
|
||||
else
|
||||
render :edit, status: :unprocessable_entity
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
@contestant.destroy
|
||||
redirect_to contest_path(@contest)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def set_contest
|
||||
@contest = Contest.find(params[:contest_id])
|
||||
end
|
||||
|
||||
def set_contestant
|
||||
@contestant = Contestant.find(params[:id])
|
||||
end
|
||||
|
||||
def contestant_params
|
||||
params.expect(contestant: [ :email, :name ])
|
||||
end
|
||||
end
|
@@ -8,6 +8,7 @@ class ContestsController < ApplicationController
|
||||
|
||||
def show
|
||||
@title = @contest.name
|
||||
@contestants = @contest.contestants
|
||||
@puzzles = @contest.puzzles
|
||||
set_badges
|
||||
end
|
||||
|
@@ -1,13 +1,6 @@
|
||||
class PuzzlesController < ApplicationController
|
||||
before_action :set_contest
|
||||
before_action :set_puzzle, only: %i[ edit destroy show update]
|
||||
|
||||
def index
|
||||
@puzzles = Puzzle.all
|
||||
end
|
||||
|
||||
def show
|
||||
end
|
||||
before_action :set_puzzle, only: %i[ destroy edit update]
|
||||
|
||||
def edit
|
||||
@title = "Edit contest puzzle"
|
||||
|
Reference in New Issue
Block a user