From 1bc945a9874722d1e0d236265f607f6fa78f609d Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Sat, 4 Nov 2023 10:02:01 -0400 Subject: show player's own solution on show page --- app/controllers/wittle/puzzles_controller.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'app/controllers') diff --git a/app/controllers/wittle/puzzles_controller.rb b/app/controllers/wittle/puzzles_controller.rb index b481460..8dc2ac8 100644 --- a/app/controllers/wittle/puzzles_controller.rb +++ b/app/controllers/wittle/puzzles_controller.rb @@ -22,6 +22,14 @@ module Wittle @puzzle = Puzzle.find(params[:id]) @playable = @puzzle.latest? && !((session[:played_puzzles] || []).include? @puzzle.id) @already_started = ((session[:started_puzzles] || []).include? @puzzle.id) + + unless @playable + if (session[:puzzle_solutions] || {}).has_key? @puzzle.id.to_s + @solution = session[:puzzle_solutions][@puzzle.id.to_s] + else + @solution = @puzzle.solved_data + end + end end def start @@ -45,6 +53,9 @@ module Wittle session[:played_puzzles] ||= [] session[:played_puzzles] << @puzzle.id + + session[:puzzle_solutions] ||= {} + session[:puzzle_solutions][@puzzle.id] = params[:solved] end def submit -- cgit 1.4.1