Rails 3.1: accepts_nested_attributes_for and has_one association - won't work?

后端 未结 2 1598
别那么骄傲
别那么骄傲 2021-01-12 04:09

I\'m trying to use accepts_nested_attributes_for on a has_one association model, and getting absolutely nowhere :-(

I have two models, a user and a location. A user

2条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-12 04:40

    <%= fields_for(@user.location) do |location_fields| %>
    

    This is your problem. You need to actually "nest" the fields_for inside your form, like this:

    <% f.fields_for(@user.location) do |location_fields| -%>
    

提交回复
热议问题