From dd84a8f87ad52012c4ab5a6caafdb86fe116b1d7 Mon Sep 17 00:00:00 2001 From: Mateus Pereira Date: Mon, 6 Oct 2025 14:10:55 -0300 Subject: [PATCH 1/4] Add "Sent" column to the archived table --- app/views/puzzles/_puzzles_table.html.erb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app/views/puzzles/_puzzles_table.html.erb b/app/views/puzzles/_puzzles_table.html.erb index a691e41..1d9ee72 100644 --- a/app/views/puzzles/_puzzles_table.html.erb +++ b/app/views/puzzles/_puzzles_table.html.erb @@ -5,6 +5,9 @@ Answer Explanation Link + <% if actions == :archived %> + Sent + <% end %> Actions @@ -20,6 +23,9 @@   <% end %> + <% if actions == :archived %> + <%= time_ago_in_words(puzzle.sent_at) %> ago + <% end %> <% if actions == :pending %> <%= button_to 'Approve', puzzle_state_path(puzzle, state: :approved), method: :patch, form_class: 'inline-form', class: 'btn approve-btn' %> From 7395af737c4f81b545281a89b73e1ebc326e458d Mon Sep 17 00:00:00 2001 From: Mateus Pereira Date: Mon, 6 Oct 2025 14:11:13 -0300 Subject: [PATCH 2/4] Add custom archived scope for ordering --- app/models/puzzle.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/models/puzzle.rb b/app/models/puzzle.rb index 773c482..11a9f16 100644 --- a/app/models/puzzle.rb +++ b/app/models/puzzle.rb @@ -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 From 227611c6ba6177fb171061efffb2badbe354448d Mon Sep 17 00:00:00 2001 From: Mateus Pereira Date: Mon, 6 Oct 2025 15:05:25 -0300 Subject: [PATCH 3/4] Add `time_ago` helper method --- app/helpers/puzzles_helper.rb | 3 +++ app/views/puzzles/_puzzles_table.html.erb | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/app/helpers/puzzles_helper.rb b/app/helpers/puzzles_helper.rb index 206d9cc..25133d2 100644 --- a/app/helpers/puzzles_helper.rb +++ b/app/helpers/puzzles_helper.rb @@ -1,2 +1,5 @@ module PuzzlesHelper + def time_ago(past_time) + "#{time_ago_in_words(past_time)} ago" + end end diff --git a/app/views/puzzles/_puzzles_table.html.erb b/app/views/puzzles/_puzzles_table.html.erb index 1d9ee72..4e0e2f0 100644 --- a/app/views/puzzles/_puzzles_table.html.erb +++ b/app/views/puzzles/_puzzles_table.html.erb @@ -24,7 +24,7 @@ <% end %> <% if actions == :archived %> - <%= time_ago_in_words(puzzle.sent_at) %> ago + <%= time_ago(puzzle.sent_at) %> <% end %> <% if actions == :pending %> From 174831fdc3d2138c5a09c00abe0ef0ba8ed1ada1 Mon Sep 17 00:00:00 2001 From: Mateus Pereira Date: Mon, 6 Oct 2025 15:50:11 -0300 Subject: [PATCH 4/4] Remove call to class name in scope MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Juan Vásquez --- app/models/puzzle.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/puzzle.rb b/app/models/puzzle.rb index 11a9f16..c7ee3f5 100644 --- a/app/models/puzzle.rb +++ b/app/models/puzzle.rb @@ -3,5 +3,5 @@ class Puzzle < ApplicationRecord enum :state, { approved: 0, rejected: 1, pending: 2, archived: 3 } has_many :answers - scope :archived, -> { Puzzle.where(state: :archived).order(sent_at: :desc) } + scope :archived, -> { where(state: :archived).order(sent_at: :desc) } end