lundi 18 juillet 2016

Rails 5 strong params with an Array within check boxes values

Given these params:

"product"=><ActionController::Parameters {"id"=>"",
"category_ids"=><ActionController::Parameters {"2"=>"1", "3"=>"1", "4"=>"1"} ,
"name"=>"...", "description"=>"a good prod", "size"=>"2x3m", "price"=>"23$", "url_video"=>"http://...", "remarks"=>"bla"} 

I want to cath category_ids params {"2"=>"1", "3"=>"1", "4"=>"1"} with the correct permit and require sintax, than I don't know:

when execute

params.require(:product).permit(:name, :size,..., category_ids: [] )

the result is

Unpermitted parameters: id, category_ids

I have tried params.require(:product).permit(:category_ids[:id,:val])... and other variants

what is the correct sintax?

PD: These params are the result of , for example:

<input type="checkbox" name="product[category_ids][2]" id="product_category_ids_2" value="1">
<input type="checkbox" name="product[category_ids][3]" id="product_category_ids_3" value="1">

for a has_and_belongs_to_many relation

Thanks a lot!




Aucun commentaire:

Enregistrer un commentaire