This project is archived and is in readonly mode.
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
- 
            
        

Nate Wiger February 19th, 2009 @ 09:03 PM
- Tag set to 2.3, edge, fields_for, form_for, form_helper, patch
 
Ok, easiest patch ever. Against trunk.
 - 
        

Eloy Duran February 20th, 2009 @ 08:32 AM
- Assigned user set to Eloy Duran
 
 - 
        

Eloy Duran February 20th, 2009 @ 08:58 PM
Please also add test coverage, for the case that args.last[:builder] was nil and was already set. Also, does this already work this way with the regular fields_for?
 - 
        

Michael Koziarski February 22nd, 2009 @ 02:27 AM
- Milestone cleared.
 
 - 
        

Eloy Duran February 26th, 2009 @ 11:41 AM
Fixed.
Note: In the doc part of the patch I thought only the top part of the file's documentation was over 80 columns wide, so I changed it to max. 80 cols. Then I realized that the rest of the file had the same problem. I'll have a talk with Pratik about standardizing this.
 - 
        

Eloy Duran February 26th, 2009 @ 12:47 PM
- Assigned user changed from Eloy Duran to Michael Koziarski
 
 - 
        

Repository February 27th, 2009 @ 12:57 PM
(from [3d1d422b8be027417cb640416d154171e75f03d1]) Pass a custom form builder on to nested fields_for calls. [#2023 status:committed]
Signed-off-by: David Heinemeier Hansson david@loudthinking.com http://github.com/rails/rails/co...
 - 
        

DHH February 27th, 2009 @ 12:58 PM
- State changed from new to committed
 
 
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>
People watching this ticket
Attachments
Referenced by
- 
        
          2023 
          form_for builder not passed to fields_for in nested forms
        (from [3d1d422b8be027417cb640416d154171e75f03d1]) Pass a ...