From a220c233fa86beffa63637682ff79c1c4211a789 Mon Sep 17 00:00:00 2001 From: swag Date: Mon, 29 May 2023 00:14:47 -0400 Subject: [PATCH] Clean-up 404 for remark->by_id --- lib/PostText/Controller/Remark.pm | 13 ++++--------- templates/remark/by_id.html.ep | 4 ++-- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/lib/PostText/Controller/Remark.pm b/lib/PostText/Controller/Remark.pm index 07a07cc..8ec9a1d 100644 --- a/lib/PostText/Controller/Remark.pm +++ b/lib/PostText/Controller/Remark.pm @@ -6,15 +6,10 @@ sub by_id($self) { my $remark_id = $self->param('remark_id'); my $remark = $self->remark->by_id($remark_id); - if (my $remark_id = $remark->{'id'}) { - $self->stash(remark => $remark) - } - else { - $self->stash( - remark => {}, - error => 'Remark not found 🤷' - ) - } + $self->stash(remark => $remark); + + $self->stash(error => 'Remark not found 🤷') + unless keys %{$remark}; $self->render; } diff --git a/templates/remark/by_id.html.ep b/templates/remark/by_id.html.ep index c9f6a98..a213941 100644 --- a/templates/remark/by_id.html.ep +++ b/templates/remark/by_id.html.ep @@ -1,12 +1,12 @@ % layout 'default'; % title my $remark_id = $remark->{'id'} ? "Remark #$remark_id" : '?';

<%= title %>

-<% if (my $remark_id = $remark->{'id'}) { =%> +<% if (keys %{$remark}) { =%>

<%= $remark->{'date'} %> - #<%= $remark_id %> + #<%= $remark->{'id'} %>