[英]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: 然后在CanCan中我有以下内容:
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. 我将CanCan用户var更改为current_user,然后做到了。 I think the two users were confusing each other. 我认为这两个用户彼此混淆。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.