2011-06-13 68 views
1

如何设置允许用户只编辑自己的配置文件的功能?编辑链接放在自己的页面显示,像这样:如何使用cancan停止用户编辑其他用户配置文件?

<% if can? :update, User %> 
    <div class="button"> 
    <%= link_to 'edit my profile', edit_user_path(@user) %> 
    </div> 
<% end %> 

的能力目前看起来是这样的:

if user.role == "author" 
    can :create, Review 
    can :update, Review do |review| 
    review.try(:user) == user 
    end 
    can :update, User, :id => user.id 
end 

我在用户控制器load_and_authorize_resource了。

但是,这不起作用,用户(作者的角色)仍然可以看到并使用所有用户显示页面上的编辑按钮。

我在这里做错了什么?

非常感谢任何帮助,非常感谢!

回答

4

应该是:

<% if can? :update, @user %> 

你需要,而不是通过类的实际对象实例。

+0

非常感谢它现在的作品! – Dave 2011-06-13 21:49:47

相关问题