Skip to content

Instantly share code, notes, and snippets.

@tombruijn
Created February 21, 2013 13:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tombruijn/5004868 to your computer and use it in GitHub Desktop.
Save tombruijn/5004868 to your computer and use it in GitHub Desktop.
CanCan + strong_parameters easiest hack
# 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