Begin a view-author page.
This commit is contained in:
parent
7579138d99
commit
a1aeb653bf
|
@ -19,6 +19,7 @@ sub startup ($self) {
|
|||
$r->get('/logout')->to('auth#logout');
|
||||
$r->get('/book/page/<page_number:num>')->to('book#index')->name('book_page');
|
||||
$r->get('/author/page/<page_number:num>')->to('book#author')->name('author_page');
|
||||
$r->get('/view_author/<id:num>')->to('book#view_author')->name('view_author');
|
||||
|
||||
# Put a route under athentication.
|
||||
my $auth = $r->under(
|
||||
|
|
|
@ -26,4 +26,11 @@ sub author ($self) {
|
|||
);
|
||||
}
|
||||
|
||||
sub view_author ($self) {
|
||||
my $id = $self->param('id');
|
||||
$self->render(
|
||||
author => MyModel::Author->new->find_by_id($id)
|
||||
);
|
||||
}
|
||||
|
||||
1;
|
||||
|
|
|
@ -19,5 +19,12 @@ sub get_page ($self, $page_number = 1, $name_like = undef) {
|
|||
return $rs;
|
||||
}
|
||||
|
||||
sub find_by_id ($self, $id) {
|
||||
return $self->schema->resultset('Author')->find(
|
||||
{ id => $id },
|
||||
{ prefetch => [ "books" ] },
|
||||
);
|
||||
}
|
||||
|
||||
no Moose;
|
||||
__PACKAGE__->meta->make_immutable;
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
</tr>
|
||||
% for my $author ($author_page->all) {
|
||||
<tr>
|
||||
<td><%= $author->name %></td>
|
||||
<td><%= link_to($author->name => 'view_author' => { id => $author->id}) %></td>
|
||||
</tr>
|
||||
% }
|
||||
</table>
|
||||
|
|
5
templates/book/view_author.html.ep
Normal file
5
templates/book/view_author.html.ep
Normal file
|
@ -0,0 +1,5 @@
|
|||
% layout 'default';
|
||||
% title 'Author: ' . $author->name;
|
||||
<h1>Author: <%= $author->name %></h1>
|
||||
|
||||
<strong><%= $author->name %></strong> wrote <%= $author->books->count %> books.
|
Loading…
Reference in New Issue
Block a user