In rails (with cancan or otherwise) I want the logged in user to be able to edit some of their database record but not all.
The database looks something like this:
User: name, password, team_id, role_id, notes
Role: name
Team: name
For instance, if the current_user
(the one that is logged in) has a role of user
then the only thing I want them to be able to do is change their own password. I don't want them to be able to rename themselves or change their team. I want managers to be able to add notes about themselves and other users but not other managers.
I am using a modified form of the following to do authentication:
- http://railscasts.com/episodes/250-authentication-from-scratch
- http://railscasts.com/episodes/192-authorization-with-cancan
I was thinking of adding something like the following in ability.rb
:
can :edit, User, :id => user.id
My questions are as follows:
- How do I restrict the fields that I want them to have access to?
- Where should this go, I was thinking in the controller not the model. (as I think stuff that deal with the current user permissions should not be in the model layer)