开发者

Rails 3 - CanCan to edit the current user

When a user is looking at a user profile page, if the current user == the user profile I want to show an edit button...

So I have the following in the view:

    <% if can? :update, @user %>
        <%= link_to 'Edit', edit_user_registration_path %>
  开发者_开发知识库  <% end %>

And then in CanCan I have the following:

def initialize(user)
.
.
.
can :update, User do |user2|
  user2.try(:id) == user.id
end

But this is always equaling yes. not sure why? ideas


I change the CanCan user var to current_user and that did it. I think the two users were confusing each other.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜