Reputation: 1349
I know when you want to check the ability, you do
can :read, Project, id:3
However, what if I wanted to create a page that showed all the users that could read Project #3?
In that page, how would I show all the users that had :read access to the specific project?
Something like
<% User.all.each do |u| %>
<% if u can :read, Project, id:3 %>
<%= u.name %>
<% end %>
<% end %>
Upvotes: 1
Views: 2929
Reputation: 5802
Cancan has documentation for this: https://github.com/ryanb/cancan/wiki/Checking-Abilities
Based on your example:
include CanCan::Ability
project = Project.find(3)
User.all.each do |u|
if u.can? :read, project
#print the user or something
end
end
Upvotes: 0
Reputation: 1349
Looks like there was a wiki on this issue:
https://github.com/ryanb/cancan/wiki/ability-for-other-users
Upvotes: 0