diff options
author | Star Rauchenberger <fefferburbia@gmail.com> | 2023-10-29 11:32:06 -0400 |
---|---|---|
committer | Star Rauchenberger <fefferburbia@gmail.com> | 2023-10-29 11:32:06 -0400 |
commit | 10599ab2e789ffb93a19f6aa3c100f533c460315 (patch) | |
tree | f49edb1c44fe698e023a73ee82c1584b328cb5de /app/controllers | |
parent | 141f8b1a7e42928e94cccd0c8f89fdd56f8e2efe (diff) | |
download | wittle-10599ab2e789ffb93a19f6aa3c100f533c460315.tar.gz wittle-10599ab2e789ffb93a19f6aa3c100f533c460315.tar.bz2 wittle-10599ab2e789ffb93a19f6aa3c100f533c460315.zip |
generate, show, solve puzzles
Diffstat (limited to 'app/controllers')
-rw-r--r-- | app/controllers/wittle/puzzles_controller.rb | 36 |
1 files changed, 35 insertions, 1 deletions
diff --git a/app/controllers/wittle/puzzles_controller.rb b/app/controllers/wittle/puzzles_controller.rb index 09a2524..9599307 100644 --- a/app/controllers/wittle/puzzles_controller.rb +++ b/app/controllers/wittle/puzzles_controller.rb | |||
@@ -1,7 +1,41 @@ | |||
1 | module Wittle | 1 | module Wittle |
2 | class PuzzlesController < ApplicationController | 2 | class PuzzlesController < ApplicationController |
3 | def about | ||
4 | @normal_puzzle = Puzzle.normal.order(created_at: :desc).first | ||
5 | @hard_puzzle = Puzzle.hard.order(created_at: :desc).first | ||
6 | end | ||
7 | |||
3 | def index | 8 | def index |
4 | @puzzle = WittleGenerator.new.generate_medium | 9 | #@puzzle = WittleGenerator.new.generate_medium |
10 | end | ||
11 | |||
12 | def show | ||
13 | @puzzle = Puzzle.find(params[:id]) | ||
14 | @playable = @puzzle.latest? && !((session[:played_puzzles] || []).include? @puzzle.id) | ||
15 | end | ||
16 | |||
17 | def solve | ||
18 | @puzzle = Puzzle.find(params[:id]) | ||
19 | |||
20 | raise ActiveRecord::RecordNotFound unless @puzzle.latest? | ||
21 | |||
22 | if @puzzle.solved_data.nil? | ||
23 | @puzzle.solved_data = params[:solved] | ||
24 | @puzzle.save! | ||
25 | end | ||
26 | |||
27 | session[:played_puzzles] ||= [] | ||
28 | session[:played_puzzles] << @puzzle.id | ||
29 | end | ||
30 | |||
31 | def submit | ||
32 | @puzzle = Puzzle.find(params[:id]) | ||
33 | |||
34 | raise ActiveRecord::RecordNotFound unless @puzzle.latest? | ||
35 | |||
36 | @puzzle.scores.create!(name: params[:name], ip: request.ip) | ||
37 | |||
38 | redirect_to @puzzle | ||
5 | end | 39 | end |
6 | end | 40 | end |
7 | end | 41 | end |