Question

= f.field_for @user.account || @user.build_account do |account|
  = account.text_field :name

Is generating

<input name="user[account][name]">

and I want:

<input name="user[account_attributes][name]">

what am I doing wrong?

Était-ce utile?

La solution

What I needed was:

= f.fields_for :account, @user.account || @user.build_account do |account|

Autres conseils

Passing by, I would like to mention the object_name method

account.object_name should return "user[account_attributes]"

So if you concatenate your field name between brackets "[field_name]", you can easily construct the right name for your input's field

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top