cancan icon indicating copy to clipboard operation
cancan copied to clipboard

Nested Resource loads incorrectly in CanCan 1.6.6

Open JDutil opened this issue 15 years ago • 15 comments

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
end

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.

JDutil avatar Sep 29 '11 03:09 JDutil

I can confirm this as well.

bidigo avatar Sep 29 '11 13:09 bidigo

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

tanguygo avatar Sep 29 '11 15:09 tanguygo

Also happening to me.

seanmcoleman avatar Sep 29 '11 19:09 seanmcoleman

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.

nschmoller avatar Sep 30 '11 10:09 nschmoller

Confirmed here also. Had to revert to 1.6.5.

marclennox avatar Oct 01 '11 04:10 marclennox

Same issue here.

sush avatar Oct 02 '11 15:10 sush

Here, too

hquick81 avatar Oct 03 '11 00:10 hquick81

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

dnagir avatar Oct 03 '11 00:10 dnagir

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

Downgraded to 1.6.5 to fix the issue.

pwgustafson avatar Oct 03 '11 22:10 pwgustafson

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

emilianodellacasa avatar Oct 04 '11 13:10 emilianodellacasa

Same error here. 1.6.6 should be yanked.

gucki avatar Oct 04 '11 20:10 gucki

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.

https://github.com/ryanb/cancan/pull/424

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.

ryanb avatar Oct 04 '11 22:10 ryanb

Thank a lot Ryan.

dnagir avatar Oct 04 '11 22:10 dnagir

When will people start sending patches instead?

kurko avatar Oct 05 '11 03:10 kurko

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.

https://github.com/galetahub/cancan_namespace/

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?

Thanks,

georgegwu avatar Mar 10 '12 23:03 georgegwu