This project is archived and is in readonly mode.

#2023 ✓committed
Nate Wiger

form_for builder not passed to fields_for in nested forms

Reported by Nate Wiger | February 19th, 2009 @ 08:56 PM

In Rails 2.3, the nested forms support does not pass the builder to any nested fields_for calls. For example, if you say:

<% form_for(@forum_topic, :builder => MyFormBuilder) do |f| %>
  <%= f.error_messages %>
  <%= f.text_field :title %>
  <% f.fields_for :forum_post do |p| %>
    <%= p.text_area :body %>
  <% end %>
  <%= f.check_box :sticky %>
  <%= f.check_box :locked %>
  <p>
    <%= f.submit 'Create' %>
  </p>
<% end %>

The custom "MyFormBuilder" builder does not get passed into the fields_for call explicitly:

<% form_for(@forum_topic, :builder => MyFormBuilder) do |f| %>
  <%= f.error_messages %>
  <%= f.text_field :title %>
  <% f.fields_for(:forum_post, :builder => MyFormBuilder) do |p| %>
    <%= p.text_area :body %>
  <% end %>
  <%= f.check_box :sticky %>
  <%= f.check_box :locked %>
  <p>
    <%= f.submit 'Create' %>
  </p>
<% end %>

It seems like form_for should be able to store the :builder option in some type of instance variable and then pass it into fields_for blocks.

I can spin a patch, but would like an opinion on how to proceed. Looks like the FormBuilder version of fields_for would need to reference @options and pull apart *args* in vendor/rails/actionpack/lib/action_view/helpers/form_helper.rb

Comments and changes to this ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

Referenced by

Pages