How to submit multiple NEW items via Rails 3.2 mass-assignment

前端 未结 8 1468
醉梦人生
醉梦人生 2020-12-04 06:33

I have a pretty standard use-case. I have a parent object and a list of child objects. I want to have a tabular form where I can edit all the children at once, as rows in th

相关标签:
8条回答
  • 2020-12-04 07:13

    Maybe you should just cheat. Put the new records in a different faux attribute that is a decorator for the actual one.

    parent[children_attributes][0][fieldname]
    parent[new_children_attributes][][fieldname]
    

    It's not pretty, but it should work. It might take some extra effort to support round-trips to the form for validation errors.

    0 讨论(0)
  • 2020-12-04 07:13

    long post deleted

    Ryan has an episode on this: http://railscasts.com/episodes/196-nested-model-form-revised

    It looks like you need to generate the unique index manually. Ryan uses the object_id for this.

    0 讨论(0)
提交回复
热议问题