Created
February 21, 2013 13:54
-
-
Save tombruijn/5004868 to your computer and use it in GitHub Desktop.
CanCan + strong_parameters easiest hack
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# From: https://github.com/ryanb/cancan/pull/757 | |
# Here for reference | |
## | |
# Tell CanCan to use the user-controller resource_params method | |
# rather than its own (when the user-method) is available | |
module CanCan | |
class ControllerResource | |
def resource_params | |
return @controller.send(:resource_params) if @controller.respond_to?(:resource_params) | |
super | |
end | |
end | |
end | |
## | |
# Then make a (public) resource_params method in your own controller | |
# Where you use strong_parameters | |
def create | |
Site.new resource_params | |
end | |
def resource_params | |
aparams = params[:site] | |
aparams.permit(:name) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment