It’s my first time here, and first time I use nested_form gem. Everything seemed to be ok, but the data from my “parent” model doesn’t save.
Here is my code
<%= nested_form_for @project do |f| %>
<p>
<%= f.label :name %><br />
<%= f.text_field :name %>
</p>
<%= f.fields_for :tasks %>
<p><%= f.link_to_add "Add a task", :tasks %></p>
<%= f.submit %>
<% end %>
so, when I “submit”, just the tasks are saved ok, but not the project name.
Any clue for me? did I miss something??
Your fields_for declaration isn’t quite right
Should be
you are also missing an end for that declaration and a render to render the partial that has the nested fields for the associated object.
So you should end up with something like this
That should do the trick. all you need to do now is create a _task_field.html.erb partial and add the task fields to it in the usual way using f.label, f.text_field etc…
p.s.
Your code could not possibly have ever worked. You would have had errors so something is probably missing from your opening post.