Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
3 changes: 3 additions & 0 deletions app/helpers/puzzles_helper.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
module PuzzlesHelper
def time_ago(past_time)
"#{time_ago_in_words(past_time)} ago"
end
end
2 changes: 2 additions & 0 deletions app/models/puzzle.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@ class Puzzle < ApplicationRecord
enum :answer, ruby: 0, rails: 1
enum :state, { approved: 0, rejected: 1, pending: 2, archived: 3 }
has_many :answers

scope :archived, -> { Puzzle.where(state: :archived).order(sent_at: :desc) }
end
6 changes: 6 additions & 0 deletions app/views/puzzles/_puzzles_table.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
<th>Answer</th>
<th>Explanation</th>
<th>Link</th>
<% if actions == :archived %>
<th>Sent</th>
<% end %>
<th>Actions</th>
</tr>
</thead>
Expand All @@ -20,6 +23,9 @@
&nbsp;
<% end %>
</td>
<% if actions == :archived %>
<td><%= time_ago(puzzle.sent_at) %></td>
<% end %>
<td>
<% if actions == :pending %>
<%= button_to 'Approve', puzzle_state_path(puzzle, state: :approved), method: :patch, form_class: 'inline-form', class: 'btn approve-btn' %>
Expand Down