Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

allow override resource_params so that it can easily work with strong…

…_parameters gem
  • Loading branch information...
commit f4778b60a1359270162ff128ec3c118e0ca8287c 1 parent b4285ae
@flyerhzm authored
View
1  lib/cancan/controller_resource.rb
@@ -212,6 +212,7 @@ def name
end
def resource_params
+ return @controller.send(:resource_params) if @controller.respond_to?(:resource_params)
if @options[:class]
params_key = extract_key(@options[:class])
return @params[params_key] if @params[params_key]
View
13 spec/cancan/controller_resource_spec.rb
@@ -471,4 +471,17 @@ class Section
lambda { resource.load_and_authorize_resource }.should_not raise_error
@controller.instance_variable_get(:@project).should be_nil
end
+
+ it "should allow override resource_params" do
+ @params.merge!(:action => "new", :project => {:title => "title"})
+ @controller.instance_exec do
+ def resource_params
+ # params.require(:project).permit(:title, :body)
+ params[:project][:body] = "body"
+ end
+ end
+ resource = CanCan::ControllerResource.new(@controller, :project)
+ resource.load_resource
+ @params[:project][:body].should == "body"
+ end
end
Please sign in to comment.
Something went wrong with that request. Please try again.