0

I want to create several objects at a time, from my index view, so I have inputs: post[][title] and post[][parent_id], in my post_controller.rb i have:

def post_params
  params.require(:post).permit(:title => [], :parent_id => [])
end

But I'm getting the error on submit: undefined method 'permit' for [{"title"=>"Title", "parent_id"=>"133"}]:Array

I read this post, but if I try params.permit(:title => [], :parent_id => []), then post_params just returns empty hash.

params:

{"utf8"=>"✓",
"authenticity_token"=>"oJwfzxbn+LJ/pD1hKo27gckZg6P4Gd8wyNY9NSFS4BA=",
"post"=>{"title"=>["1",
"2"],
"parent_id"=>["",
""]},
"locale"=>"ru"}
Community
  • 1
  • 1
Max Filippov
  • 2,024
  • 18
  • 37

1 Answers1

0

The problem was in Cancancan strong params, despite the following article I could not get cancancan gem to use my post_params function (i have load_and_authorize_resource call in ApplicationController), so the fix was to use skip_load_resource :only => :create in my PostController.

Note: due to this issue writing skip_load_resource :only => :create in ApplicationController won't work.

Max Filippov
  • 2,024
  • 18
  • 37