Skip to content

Commit 544ccd7

Browse files
authored
Show "Sent" date in a readable format (#34)
1 parent 7e54bb3 commit 544ccd7

File tree

3 files changed

+11
-0
lines changed

3 files changed

+11
-0
lines changed

app/helpers/puzzles_helper.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
module PuzzlesHelper
2+
def time_ago(past_time)
3+
"#{time_ago_in_words(past_time)} ago"
4+
end
25
end

app/models/puzzle.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@ class Puzzle < ApplicationRecord
22
enum :answer, ruby: 0, rails: 1
33
enum :state, { approved: 0, rejected: 1, pending: 2, archived: 3 }
44
has_many :answers
5+
6+
scope :archived, -> { where(state: :archived).order(sent_at: :desc) }
57
end

app/views/puzzles/_puzzles_table.html.erb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
<th>Answer</th>
66
<th>Explanation</th>
77
<th>Link</th>
8+
<% if actions == :archived %>
9+
<th>Sent</th>
10+
<% end %>
811
<th>Actions</th>
912
</tr>
1013
</thead>
@@ -20,6 +23,9 @@
2023
&nbsp;
2124
<% end %>
2225
</td>
26+
<% if actions == :archived %>
27+
<td><%= time_ago(puzzle.sent_at) %></td>
28+
<% end %>
2329
<td>
2430
<% if actions == :pending %>
2531
<%= button_to 'Approve', puzzle_state_path(puzzle, state: :approved), method: :patch, form_class: 'inline-form', class: 'btn approve-btn' %>

0 commit comments

Comments
 (0)