ryanb/cancan — pull request #911 by blischalk (2013-07-28 16:58:03+00:00)
Title: Isue #835 - CanCan ActiveModel::ForbiddenAttributesError with rails 4

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.