puzzle-scoreboard/app/controllers/puzzles_controller.rb
sto 50280ce389
Some checks are pending
CI / scan_ruby (push) Waiting to run
CI / scan_js (push) Waiting to run
CI / lint (push) Waiting to run
CI / test (push) Waiting to run
Initial app
2025-03-14 15:36:05 +01:00

39 lines
599 B
Ruby

class PuzzlesController < ApplicationController
before_action :set_puzzle, only: %i[ show destroy ]
def index
@puzzles = Puzzle.all
end
def show
end
def new
@puzzle = Puzzle.new
end
def create
@puzzle = Puzzle.new(puzzle_params)
if @puzzle.save
redirect_to @puzzle
else
render :new, status: :unprocessable_entity
end
end
def destroy
@puzzle.destroy
redirect_to puzzles_path
end
private
def set_puzzle
@puzzle = Puzzle.find(params[:id])
end
def puzzle_params
params.expect(puzzle: [ :name, :image ])
end
end