Initial app
This commit is contained in:
38
app/controllers/puzzles_controller.rb
Normal file
38
app/controllers/puzzles_controller.rb
Normal file
@@ -0,0 +1,38 @@
|
||||
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
|
||||
Reference in New Issue
Block a user