2012-07-17 82 views
0

我有一個簡單的設置與坎康和設計。CanCan,Devise和「current_user」

我想告訴編輯按鈕只能以「管理員」,並擁有「位置」的用戶:

所以在show.html.erb我

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

我ability.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:我的角色存儲在一個數組中,例如:角色[「User」,「Admin」],並且工作正常。

回答

0

我找到了與

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

工作,我希望它可以幫助別人!

相關問題