开发者

How can I use cancan to stop a user from editing other users profiles?

How can I set an ability to allow a user to only edit their own profile? The edit link is placed in their own show page like so:

<% if can? :update, User %>
  <div class="b开发者_开发技巧utton">
    <%= link_to 'edit my profile', edit_user_path(@user) %>
  </div>
<% end %>

The ability currently looks like this:

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

I have load_and_authorize_resource in the user controller too.

But this doesn't work, the user (with role of author) can still see and use the edit button on all users show pages.

What am I doing wrong here?

Thanks very much for any help its much appreciated!


Should be:

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

You need to pass the actual object instance instead of the class.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜