0

我有一个简单的 Cancan 和 Devise 设置。

我只想向“管理员”和拥有“位置”的用户显示编辑按钮:

所以在 show.html.erb 我有

<% if can? :manage, location, :user_id == current_user.id %>
    <%= link_to 'Edit', edit_location_path %>
<% end %>

我的能力.rb 看起来像这样

if user.roles.include?('User')
  can [:show, :index, :create], Location
  can :manage, Location, :user_id => user.id
end

locationController 在最顶部包含以下内容:

load_and_authorize_resource

用户 ID 在 Location.user_id 中引用

但它没有显示编辑按钮......

我错过了什么?

PS:user.id 在视图中不起作用。并且 current_user.id 在ability.rb 中不起作用

PPS:我的角色存储在一个数组中,例如:Roles ["User", "Admin"] 并且运行良好。

4

1 回答 1

0

我有它的工作

can :manage, Location, :user_id => user.id.to_s

我希望它可以帮助某人!

于 2012-07-17T13:03:28.520 回答