Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Nested Resource loads incorrectly in CanCan 1.6.6 #482

JDutil opened this Issue Sep 29, 2011 · 15 comments


None yet

JDutil commented Sep 29, 2011

When attempting to load_and_authorize a nested resource in version 1.6.6 it will attempt to load the nested resource using the parent resources id.

My controller looks like:

class DemoWebsitesController < ApplicationController
  load_and_authorize_resource :potential_customer
  load_and_authorize_resource :demo_website, :through => :potential_customer, :singleton => true

When trying to post to demo_websites#create the params would have: potential_customer_id => 6

I would then receive the error: ActiveRecord::RecordNotFound: Couldn't find DemoWebsite with id=6

There is no parameter id mind you. It is taking the potential_customer_id param, and using it as the id param.

Downgrading back to version 1.6.5 fixes the issue.

bidigo commented Sep 29, 2011

I can confirm this as well.

I confirm too. I killed a cat because of that.

Also happening to me.

Problem is in the new support for namespaced models from whilefalse: controller_resource.rb:207

I don't know how this is supposed to work though.

Confirmed here also. Had to revert to 1.6.5.

sush commented Oct 2, 2011

Same issue here.

hjansen commented Oct 3, 2011

Here, too

dnagir commented Oct 3, 2011

Same issue here as well. 1.6.6 broke the world :)

I'm also getting this issue...using 1.6.6

Downgraded to 1.6.5 to fix the issue.

The same here using 1.6.6, had to downgrade to 1.6.5 to fix it right away

gucki commented Oct 4, 2011

Same error here. 1.6.6 should be yanked.

@ryanb ryanb closed this in 67a3038 Oct 4, 2011


ryanb commented Oct 4, 2011

Sorry for the problem, I just released 1.6.7 with a quick fix and pulled 1.6.6. This issue was originally caused by this pull request.


The reason it got through the tests is because there was no controller name specified which matched an existing constant while loading the parent resource. The test case has been updated to handle this specific situation so it shouldn't crop up again.

That said, I think there's a better way to handle namespaced resources. If someone wants to submit a pull request feel free.

dnagir commented Oct 4, 2011

Thank a lot Ryan.

kurko commented Oct 5, 2011

When will people start sending patches instead?

Ryan> Not sure if this is directly related.

I am trying to define ability for namespaced controller. I can not find any documentation on how to and find this instead.


I like the way it proposed to work, but don't know how well it works together with current version cancan 1.6.7.

Any recommendation or pointer?


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment