about summary refs log tree commit diff stats
path: root/app/controllers
diff options
context:
space:
mode:
Diffstat (limited to 'app/controllers')
-rw-r--r--app/controllers/wittle/puzzles_controller.rb36
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 @@
1module Wittle 1module 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
7end 41end