I am working on a Model with an atter_accessor object named element. I want to pass the Array of form data to the element object. In Rails console I am getting Unpermitted parameter error.
Parameters: {"authenticity_token"=>"[FILTERED]", "category"=>{"name"=>"asfd", "body"=>"asf", "element"=>{"1"=>"asfd:text", "2"=>"asfd:text", "3"=>"asfd:text"}}, "type"=>"text", "commit"=>"Create Category"}
Unpermitted parameter: :element. Context: { controller: CategoriesController, action: create, request: #<ActionDispatch::Request:0x0000000106b3ff68>, params: {"authenticity_token"=>"[FILTERED]", "category"=>{"name"=>"asfd", "body"=>"asf", "element"=>{"1"=>"asfd:text", "2"=>"asfd:text", "3"=>"asfd:text"}}, "type"=>"text", "commit"=>"Create Category", "controller"=>"categories", "action"=>"create"} }
In model attr_accessor :elements
In controller
def category_params
params.require(:category).permit(:name, :body, :elements => [])
end
I tried with many alternatives changing the :elements
to element: []
too, nothing worked. I think I am missing something here which is the reason I am getting an unpermitted parameters.
params.permit(:name, :body, element: [])
params.permit(:name, :body, :element)
?attr_accessor :element
toattr_accessor :elements
so that your team work or other people who read your question will not misunderstanding