RailsCasts Pro episodes are now free!

Learn more or hide this

Matt London's Profile

GitHub User: mattlondon

Comments by Matt London


You can accomplish this on the server side by building the nested object in your view. Use the "build_(association name)" method, which is provided by Active Record.

Inside the _action_fields.html.erb partial:

<%= f.label :step_height, "Step Height (in feet)" %>
<%= f.text_field :step_height %>

<% f.object.build_action %>  **HERE**

<%= f.fields_for :action do |builder| %>
  <%= render 'action_fields', f: builder %>
<% end %>

Now the fields_for :action block will execute and render the action_fields partial.

Naturally you would want to use this in the sub-nested partials as well.