Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions app/models/puzzle.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 5 additions & 3 deletions app/views/puzzles/_puzzles_table.html.erb
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can imaging that if the puzzle was cloned that we may want to know how many correct answers there were for the original question - but this number may be more suited to the Pending table.

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
<th>Answer</th>
<th>Explanation</th>
<th>Link</th>
<% if actions == :archived %>
<% if actions.in?([:approved, :archived]) %>
<th>Correct %</th>
<th>Sent</th>
<% end %>
<th>Actions</th>
Expand All @@ -23,8 +24,9 @@
&nbsp;
<% end %>
</td>
<% if actions == :archived %>
<td><%= time_ago(puzzle.sent_at) %></td>
<% if actions.in?([:approved, :archived]) %>
<td><%= puzzle.correct_answer_percentage %>%</td>
<td><%= time_ago(puzzle.sent_at) if puzzle.sent_at.present? %></td>
<% end %>
<td>
<% if actions == :pending %>
Expand Down