Skip to content

Instantly share code, notes, and snippets.

@paukul
Created March 15, 2013 14:44
Show Gist options
  • Save paukul/5170332 to your computer and use it in GitHub Desktop.
Save paukul/5170332 to your computer and use it in GitHub Desktop.
# lib/monkey/cancan/controller_resource.rb
module CanCan
class ControllerResource
protected
def strong_parameters?
@params.class.name == 'ActionController::Parameters'
end
def resource_params
if [:create, :update].member? @params[:action].to_sym
param_name = @options[:instance_name] || (@options[:class] || namespaced_name).to_s.underscore.gsub('/', '_')
if strong_parameters? || @options[:params]
params_method = (@options[:params] == true || ! @options[:params]) ?
"#{param_name}_params" : @options[:params]
return @controller.send params_method if @controller.send :respond_to?, params_method
end
@params[param_name]
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment