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..694c9ae 100644 --- a/app/views/puzzles/_puzzles_table.html.erb +++ b/app/views/puzzles/_puzzles_table.html.erb @@ -5,7 +5,8 @@ Answer Explanation Link - <% if actions == :archived %> + <% if actions.in?([:approved, :archived]) %> + Correct % Sent <% end %> Actions @@ -23,8 +24,9 @@   <% end %> - <% if actions == :archived %> - <%= time_ago(puzzle.sent_at) %> + <% if actions.in?([:approved, :archived]) %> + <%= puzzle.correct_answer_percentage %>% + <%= time_ago(puzzle.sent_at) if puzzle.sent_at.present? %> <% end %> <% if actions == :pending %>