puzzle-scoreboard/app/controllers/puzzles_controller.rb
sto b8674a126f
All checks were successful
CI / scan_ruby (push) Successful in 16s
CI / scan_js (push) Successful in 12s
CI / lint (push) Successful in 13s
CI / test (push) Successful in 37s
Back buttons
2025-06-18 19:09:55 +02:00

67 lines
1.3 KiB
Ruby

class PuzzlesController < ApplicationController
before_action :set_contest
before_action :set_puzzle, only: %i[ destroy edit update]
def edit
authorize @contest
@action_name = t("helpers.buttons.back")
@action_path = contest_path(@contest)
end
def new
authorize @contest
@action_name = t("helpers.buttons.back")
@action_path = contest_path(@contest)
@puzzle = Puzzle.new
end
def create
authorize @contest
@puzzle = Puzzle.new(puzzle_params)
@puzzle.contest_id = @contest.id
if @puzzle.save
redirect_to contest_path(@contest)
else
@action_name = t("helpers.buttons.back")
@action_path = contest_path(@contest)
render :new, status: :unprocessable_entity
end
end
def update
authorize @contest
if @puzzle.update(puzzle_params)
redirect_to @contest
else
@action_name = t("helpers.buttons.back")
@action_path = contest_path(@contest)
render :edit, status: :unprocessable_entity
end
end
def destroy
authorize @contest
@puzzle.destroy
redirect_to contest_path(@contest)
end
private
def set_contest
@contest = Contest.find(params[:contest_id])
end
def set_puzzle
@puzzle = Puzzle.find(params[:id])
end
def puzzle_params
params.expect(puzzle: [ :brand, :name, :image ])
end
end