I am working on a Ruby on Rails 3 web application.
I have a table named User
with a coulmn named role
. I am looking for the best way to hide parts of the view from users that have the "wrong" role for those parts of the view.
For example I want all users to be able to see the users index
page, but i want only users with a role - admin
to be able to edit other users.
So first I block the edit
action using filter_by
, but what I also want is make the edit
button not to appear.
The current user is saved in the session, so checking the user role is very simple.
What I am asking, is there an easy way to do so besides the obvious if
statement before each button I want to hide. I would think that rails would have an easy way to do this type of thing, I couldn't find one.