-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpuzzles_controller.rb
More file actions
38 lines (32 loc) · 1.13 KB
/
puzzles_controller.rb
File metadata and controls
38 lines (32 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
class PuzzlesController < ApplicationController
def index
unless session[:user_token]
render "login"
end
@pending_puzzles = Puzzle.pending
@approved_puzzles = Puzzle.approved
@rejected_puzzles = Puzzle.rejected
@archived_puzzles = Puzzle.archived
end
def edit
@puzzle = Puzzle.find(params[:id])
end
def update
@puzzle = Puzzle.find(params[:id])
respond_to do |format|
if @puzzle.update(puzzle_params)
format.turbo_stream
format.html { redirect_to puzzles_path, notice: "Puzzle updated." }
format.json { render json: { success: true, puzzle: @puzzle } }
else
format.turbo_stream { render turbo_stream: turbo_stream.replace("modal", partial: "puzzles/edit_modal", locals: { puzzle: @puzzle }), status: :unprocessable_entity }
format.html { render :edit, status: :unprocessable_entity }
format.json { render json: { success: false, errors: @puzzle.errors.full_messages }, status: :unprocessable_entity }
end
end
end
private
def puzzle_params
params.require(:puzzle).permit(:question, :answer, :explanation, :link)
end
end