cancan icon indicating copy to clipboard operation
cancan copied to clipboard

Isue #835 - CanCan ActiveModel::ForbiddenAttributesError with rails 4

Open blischalk opened this issue 11 years ago • 14 comments

I recently ran into the issue of getting the ForbiddenAttribuesError when using CanCan on a Rails 4 app that I am building. After looking into the issue it appears that the problem is that when load_and_authorize_resource is used in a controller it loads up the resource using the params straight from the controller before they have been sanitized.

My approach was to add the ability to specify the params method defined in the controller as an argument to load_and_authorize_resource. E.g load_and_authorize_resource attributes: :my_method. This method is then used to grab the params to build the resource from instead of using the params straight from the controller.

I have also included a check for the params method being specified which seems to preserve backward compatibility.

blischalk avatar Jul 28 '13 16:07 blischalk

:+1:

mhenrixon avatar Aug 05 '13 09:08 mhenrixon

:+1:

dgilperez avatar Aug 13 '13 00:08 dgilperez

:+1:

Arcath avatar Sep 04 '13 11:09 Arcath

:+1:

garrettlancaster avatar Sep 06 '13 02:09 garrettlancaster

:+1:

jpascal avatar Oct 11 '13 12:10 jpascal

:+1:

binyamindavid avatar Oct 11 '13 16:10 binyamindavid

:+1:

theodorton avatar Oct 19 '13 11:10 theodorton

:+1:

mzahir avatar Oct 26 '13 18:10 mzahir

I've added a pull request for this branch where you don't have to define the method as it would default to post_params for a PostController.

theodorton avatar Oct 26 '13 18:10 theodorton

:+1:

zdavis avatar Oct 27 '13 18:10 zdavis

+1

andrezimpel avatar Jan 12 '14 08:01 andrezimpel

+1

sebakri avatar Jan 21 '14 09:01 sebakri

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

:+1:

marceloboeira avatar Jan 16 '15 01:01 marceloboeira