Edit C<lib/MyApp.pm> and add C<Authorization::Roles> to the list:
# Load plugins
- use Catalyst qw/-Debug
+ use Catalyst qw/
+ -Debug
ConfigLoader
Static::Simple
'Catalyst::Plugin::Authorization::Roles' => '0',
);
+
=head2 Add Role-Specific Logic to the "Book List" Template
Open C<root/src/books/list.tt2> in your editor and add the following
<ul>
[% # Dump list of roles -%]
- [% FOR role = c.user.role %]<li>[% role %]</li>[% END %]
+ [% FOR role = c.user.roles %]<li>[% role %]</li>[% END %]
</ul>
<p>
# Add a record to the join table for this book, mapping to
# appropriate author
- $book->add_to_book_author({author_id => $author_id});
+ $book->add_to_book_authors({author_id => $author_id});
# Note: Above is a shortcut for this:
- # $book->create_related('book_author', {author_id => $author_id});
+ # $book->create_related('book_authors', {author_id => $author_id});
# Assign the Book object to the stash for display in the view
$c->stash->{book} = $book;
# Redirect the user back to the list page
$c->response->redirect($c->uri_for($self->action_for('list')));
- }
+ }
Here, we C<detach> to an error page if the user is lacking the
appropriate permissions. For this to work, we need to make
Please report any errors, issues or suggestions to the author. The
most recent version of the Catalyst Tutorial can be found at
-L<http://dev.catalyst.perl.org/repos/Catalyst/Catalyst-Manual/5.70/trunk/lib/Catalyst/Manual/Tutorial/>.
+L<http://dev.catalyst.perl.org/repos/Catalyst/Catalyst-Manual/5.80/trunk/lib/Catalyst/Manual/Tutorial/>.
Copyright 2006-2008, Kennedy Clark, under Creative Commons License
(L<http://creativecommons.org/licenses/by-sa/3.0/us/>).