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