Get an array from a Rails form

后端 未结 5 1252
野趣味
野趣味 2021-01-12 13:10

I need to design a form for a account resource. In that form, i need to collect some set of ids as an array in the params hash in attribute called

5条回答
  •  时光取名叫无心
    2021-01-12 14:07

    I'm working in something similar. My issue was how to pass the input name to a partial to resolve it as a hash using the rails form_for helper.

    So, my solutions was something like this:

    = render 'my_partial', form: form, name: "item_ids[item.id]"

    So, this gonna render an html like this:

    The number 1 is the item.id, this is how HTML understand that you gonna pass an array or hash, all depends your config.

    So, the params gonna look like this:

    "items_ids"=>{"1"=>"1"}

    This is working for me with an form_object + virtus

提交回复
热议问题