Rails - Using form_for and fields_for, how do you access the sub-object while in the fields_for block?

后端 未结 2 2065
梦毁少年i
梦毁少年i 2020-12-13 08:33

In my first rails app I\'m trying to use form_for and fields_for to create a nested object form. So far so good, but I can\'t figure out how to acc

2条回答
  •  [愿得一人]
    2020-12-13 09:19

    I just dealt with this today myself.

    You can access the object of the fields_for through:

    builder.object
    

    where builder is your fields_for form builder object. In your particular case, you can say:

    Enter license for car parked in stall: <%= builder.object.stall_number%>

    That should do it for you!

提交回复
热议问题