From 179be1f700147c752918e6c4d22f58457ffc6eee Mon Sep 17 00:00:00 2001 From: barnold Date: Wed, 12 Oct 2022 19:09:06 +0100 Subject: [PATCH] De-hardcode the book count. --- lib/MyApp/Controller/Book.pm | 5 +++++ templates/book/about.html.ep | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/MyApp/Controller/Book.pm b/lib/MyApp/Controller/Book.pm index 6ef1022..bd1859d 100644 --- a/lib/MyApp/Controller/Book.pm +++ b/lib/MyApp/Controller/Book.pm @@ -3,6 +3,11 @@ use Mojo::Base 'Mojolicious::Controller', -signatures; use MyModel::Book; use MyModel::Author; +sub about ($self) { + my $book_count = MyModel::Book->new(rows_per_page => $self->rpp)->count_all; + $self->render(book_count => $book_count); +} + sub books ($self) { my $page_number = $self->accept_posint($self->param('page_number')); if (!defined $page_number) { diff --git a/templates/book/about.html.ep b/templates/book/about.html.ep index 335781f..0988330 100644 --- a/templates/book/about.html.ep +++ b/templates/book/about.html.ep @@ -8,7 +8,8 @@ Thanks to Project Gutenberg, this is a site for looking through the book catalog they generously provide. It's a personal project and is not - affiliated with Project Gutenberg. The site currently offers 51,922 + affiliated with Project Gutenberg. The site currently offers + <%= commify($book_count) %> book records out of 68,670 in the catalog.