form_for non-AR model - fields_for Array attribute doesn't iterate

后端 未结 3 413
野趣味
野趣味 2020-12-30 09:15

I\'m having trouble getting fields_for to work on an Array attribute of a non-ActiveRecord model.

Distilled down, I have to following:

models/pa

3条回答
  •  甜味超标
    2020-12-30 10:06

    I think the correct technique is:

    = form_for @parent, :url => new_parent_path do |f|
      - @parent.bars.each do |bar|
        = f.fields_for "bars[]", bar do |r|
          = r.object.inspect
    

    Quite why it can't be made to Just Work I'm not sure, but this seems to do the trick.

提交回复
热议问题