Reputation: 622
I've rails 3 app which displays records from a DB into table. I want the same method to check if the admin controller is used and if so add edit delete options to the table items.
Example: logged in a none admin server/home/list_info
Logged in as Admin sever/admin/list_info
I've currently got two controllers and two view methods, the admin method is just a copy with the Edit Delete links on the end. This doesn't seem very DRY to me. What to people do in this situation ?
Many Thanks Andy
Upvotes: 0
Views: 71
Reputation: 25994
I think the best way is to have one set of controllers/views and simply see if the current user is an admin. If yes, show the edit/delete links.
Typically, you could use Devise for authentication and CanCan for authorization.
Devise provides a current_user object, so if you implement an admin?
method you could use something like
<%= link_to_if current_user.admin?, 'Delete', ... %>
Note: the above uses only Devise, not CanCan.
Upvotes: 1