How do I grant permission to edit/ destroy links on a by-user basis in the user index of rails?
I'm using Rails3, Devise and CanCan to define role based abilities.
I'd like the current user to be able to see and access a link to edit/delete their profile in the user index page. They should not be able to see or access these links for all other users.
I've set up the following in the index view:
<% if can? :update, @user %>
<%= link_to 'Edit', edit_user_registration_path(@user) %> |
<% end %>
And in abilities.rb
def initialize(user)
can :update, User, :id => user.id
if user.role? :super_admin
can :manage, :all
end
end
My superadmin can see and edit links for all users in the index.
My user can see links for no one, not even themselves.
The more I read around this the more confused I get, what with devise, cancan and the user model all playing a role.
I'd appreciate some confirmation that I'm on the right track, and would be grateful for any pointers towards useful information that would help me understand this.
Many thanks