0

I'm having an issue setting up an ability that looks like this:

can :read, Project, :allocate_to => user.id

The problem is

ability.can?(:read, my_project)

returns false even though

Project.accessible_by(ability)

returns just the projects for that user as expected.

I've tried cancan 1.6.10 and cancancan 1.9.2 on rails 3.2.19 with ruby 1.9.3-p547

Is this a bug with cancancan or my code? How do I find out why ability.can?(:read, my_project) is failing?

Also posted as an issue

Mark Robinson
  • 1,479
  • 2
  • 15
  • 34
  • I'm going to work around this by using authorize_resource instead of load_and_authorize_resource in my controller. This will force it to work with the class instead of the object. I think it's related to [ryanb/cancan#213](https://github.com/ryanb/cancan/issues/213) – Mark Robinson Sep 10 '14 at 13:59

1 Answers1

0

I've run into issues using the hash notation in cancan with abilities like this one. Have you tried:

can :read, Project do |project|
  project.allocate_to == user.id
end

I'm not sure why this is the case, but this has worked for me from time to time.

CDub
  • 13,146
  • 4
  • 51
  • 68