puzzle-scoreboard/app/controllers/puzzles_controller.rb
sto 0599def237
All checks were successful
CI / scan_ruby (push) Successful in 16s
CI / scan_js (push) Successful in 12s
CI / lint (push) Successful in 12s
CI / test (push) Successful in 34s
Add number of pieces to puzzles
2025-06-27 09:23:25 +02:00

67 lines
1.4 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), notice: t("puzzles.new.notice")
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, notice: t("puzzles.edit.notice")
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), notice: t("puzzles.destroy.notice")
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, :pieces ])
end
end