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
- Some info name address
- More info name address
Logged in as Admin sever/admin/list_info
- Some info name address Edit Delete
- More info name address Edit Delete
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
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 likeNote: the above uses only Devise, not CanCan.