41 lines
751 B
Ruby
41 lines
751 B
Ruby
class ContestsController < ApplicationController
|
|
before_action :set_contest, only: %i[ show destroy ]
|
|
|
|
def index
|
|
@contests = current_user.contests
|
|
@title = "Welcome #{current_user.username}!"
|
|
end
|
|
|
|
def show
|
|
@title = "Contest: #{@contest.name}"
|
|
end
|
|
|
|
def new
|
|
@contest = Contest.new
|
|
@title = "Create a new jigsaw puzzle competition"
|
|
end
|
|
|
|
def create
|
|
@contest = Contest.new(contest_params)
|
|
@contest.user_id = current_user.id
|
|
if @contest.save
|
|
redirect_to @contest
|
|
else
|
|
render :new, status: :unprocessable_entity
|
|
end
|
|
end
|
|
|
|
def destroy
|
|
end
|
|
|
|
private
|
|
|
|
def set_contest
|
|
@contest = Contest.find(params[:id])
|
|
end
|
|
|
|
def contest_params
|
|
params.expect(contest: [ :name ])
|
|
end
|
|
end
|