From a1eec7f195471134d5695b8066c749c9496cf7a2 Mon Sep 17 00:00:00 2001 From: Ernesto Tagwerker Date: Wed, 11 Feb 2026 20:25:35 -0500 Subject: [PATCH 1/2] Add correct answer % and sent_at columns to approved puzzles table Co-Authored-By: Claude Opus 4.6 --- app/models/puzzle.rb | 7 +++++++ app/views/puzzles/_puzzles_table.html.erb | 8 ++++++++ 2 files changed, 15 insertions(+) diff --git a/app/models/puzzle.rb b/app/models/puzzle.rb index 23af534..6815d81 100644 --- a/app/models/puzzle.rb +++ b/app/models/puzzle.rb @@ -8,4 +8,11 @@ class Puzzle < ApplicationRecord validates :question, presence: true scope :archived, -> { where(state: :archived).order(sent_at: :desc) } + + def correct_answer_percentage + total = answers.count + return 0 if total.zero? + + (answers.where(is_correct: true).count * 100.0 / total).round(1) + end end diff --git a/app/views/puzzles/_puzzles_table.html.erb b/app/views/puzzles/_puzzles_table.html.erb index 8b2b9e2..5891c44 100644 --- a/app/views/puzzles/_puzzles_table.html.erb +++ b/app/views/puzzles/_puzzles_table.html.erb @@ -5,6 +5,10 @@ Answer Explanation Link + <% if actions == :approved %> + Correct % + Sent + <% end %> <% if actions == :archived %> Sent <% end %> @@ -23,6 +27,10 @@   <% end %> + <% if actions == :approved %> + <%= puzzle.correct_answer_percentage %>% + <%= time_ago(puzzle.sent_at) if puzzle.sent_at.present? %> + <% end %> <% if actions == :archived %> <%= time_ago(puzzle.sent_at) %> <% end %> From 48b199fc3da3c6e2fe425770389151c0a30937f1 Mon Sep 17 00:00:00 2001 From: Ernesto Tagwerker Date: Wed, 11 Feb 2026 20:30:02 -0500 Subject: [PATCH 2/2] Add columns to the archive section --- app/views/puzzles/_puzzles_table.html.erb | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/app/views/puzzles/_puzzles_table.html.erb b/app/views/puzzles/_puzzles_table.html.erb index 5891c44..694c9ae 100644 --- a/app/views/puzzles/_puzzles_table.html.erb +++ b/app/views/puzzles/_puzzles_table.html.erb @@ -5,13 +5,10 @@ Answer Explanation Link - <% if actions == :approved %> + <% if actions.in?([:approved, :archived]) %> Correct % Sent <% end %> - <% if actions == :archived %> - Sent - <% end %> Actions @@ -27,13 +24,10 @@   <% end %> - <% if actions == :approved %> + <% if actions.in?([:approved, :archived]) %> <%= puzzle.correct_answer_percentage %>% <%= time_ago(puzzle.sent_at) if puzzle.sent_at.present? %> <% end %> - <% if actions == :archived %> - <%= time_ago(puzzle.sent_at) %> - <% end %> <% if actions == :pending %> <%= button_to 'Approve', puzzle_state_path(puzzle, state: :approved), method: :patch, form_class: 'inline-form', class: 'btn approve-btn' %>