-
Notifications
You must be signed in to change notification settings - Fork 41
Lesson Using Hydra Access Controls and CanCan to conditionally render part of a page
Michael Bond edited this page Sep 23, 2015
·
1 revision
This Tutorial is known to work with hydra-head version 6.4.0.
Please update this wiki to reflect any other versions that have been tested.
In app/views/books/show.html.erb
find the code that's displaying the "Edit" and "Back" links at the bottom of the page.
<%= link_to 'Edit', edit_book_path(@book) %> |
<%= link_to 'Back', books_path %>
Use an if ... end
clause to only show the "Edit" link if the current user has permission to edit the current book.
<%- if can?(:edit, @book) %>
<%= link_to 'Edit', edit_book_path(@book) %> |
<%- end %>
<%= link_to 'Back', books_path %>
Now go into the rails console
and give yourself edit
access to one book but only read
access for another. Look at the show views for the two books. You should see the "Edit" link on the book that you have permission to edit and you should not see the "Edit" link for the book that you do not have permission to edit.
Return to the Access Controls with Hydra tutorial.