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'} %>