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
|
||||
Reference in New Issue
Block a user