cancan icon indicating copy to clipboard operation
cancan copied to clipboard

1.6.9 -> 1.6.10 backwards compatibility issue.

Open donleyp opened this issue 11 years ago • 3 comments

I am using devise, cancan, and mongoid in a rails 3.2 application.

When I updated to cancan 1.6.10 I started receiving Mongoid::Errors::DocumentNotFound exceptions in some of my controllers. It turns out that there is a corner case that causes a backwards compatibility problem.

In a few controllers I am using load_resource to load a model object that is both optional and not directly associated with the controller. In the example I have linked it is the "User" object from the "Heck" controller. In 1.6.9 cancan loaded the resource if the corresponding parameter was passed in (e.g. user_id=ID). If the user_id parameter was not present it would simply not set the @user member variable. In 1.6.10 it calls the find method even when the parameter is not present.

Setting the mongoid option that turns off these exceptions is not an option.

While debugging I noticed that the id_param method in ControllerResource was returning a blank string instead of nil, which might explain this behavior. I tried to find the issue and submit a pull request but I could not track down a point where the parameter is queried before sending it to find.

I put together a bare minimum rails project that demonstrates the issue. You can access it on github at https://github.com/donleyp/cc_test.

donleyp avatar Jun 06 '13 00:06 donleyp

Maybe #864 fixes your problem as well?

koukou73gr avatar Jun 06 '13 22:06 koukou73gr

I bet it would. I'll try it when I get a chance. Thanks!

donleyp avatar Jun 07 '13 00:06 donleyp

Thanks for your submission! The ryanb/cancan repository has been inactive since Sep 06, 2013. Since only Ryan himself has commit permissions, the CanCan project is on a standstill.

CanCan has many open issues, including missing support for Rails 4. To keep CanCan alive, an active fork exists at cancancommunity/cancancan. The new gem is cancancan. More info is available at #994.

If your pull request or issue is still applicable, it would be really appreciated if you resubmit it to CanCanCan.

We hope to see you on the other side!

xhoy avatar Jul 01 '14 07:07 xhoy