Pregunta

= 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?

¿Fue útil?

Solución

What I needed was:

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

Otros consejos

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

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top