Skip to content

fields_for does not work with model :index #13125

Closed
bughit opened this Issue Dec 1, 2013 · 7 comments

4 participants

@bughit
bughit commented Dec 1, 2013

as the docs indicate it should
http://guides.rubyonrails.org/form_helpers.html#using-form-helpers

index makes it to here without being transformed from a model

        def tag_name_with_index(index, multiple = false)
          "#{@object_name}[#{index}][#{sanitized_method_name}]#{"[]" if multiple}"
        end
@al2o3cr
al2o3cr commented Dec 1, 2013

As on #13124, can you provide an example call to fields_for that exhibits this behavior?

@bughit
bughit commented Dec 1, 2013

there's an example in the link:

<%= form_for @person do |person_form| %>
  <%= person_form.text_field :name %>
  <% @person.addresses.each do |address| %>
    <%= person_form.fields_for address, index: address do |address_form|%>
      <%= address_form.text_field :city %>
    <% end %>
  <% end %>
<% end %>
@al2o3cr
al2o3cr commented Dec 1, 2013

I don't see anywhere where the value passed to index is being converted sensibly (presumably with to_param), but I'm also unclear on how the example in the guides worked before - the fields_for calls should have emitted hidden id fields for each of the address records as well. Will investigate further.

@JonRowe
JonRowe commented Jan 5, 2014

Hey @al2o3cr did you get any further investigating this?

@al2o3cr
al2o3cr commented Jan 6, 2014

@JonRowe - I haven't made any headway. I'm 90% sure that the guide is simply wrong and/or out-of-date - I couldn't find any evidence (in my limited source code digging) that showed passing index a model ever worked.

@JonRowe
JonRowe commented Jan 6, 2014

The section in the docs is at least 3years old, but it seems like it should work...

@pixeltrix
Ruby on Rails member

Pretty sure this is a documentation error - the example itself is over five years old and both Rails 1.2 and Rails 2.3 don't do anything with the index. The examples need updating to be address.id I guess.

@prathamesh-sonpatki prathamesh-sonpatki added a commit to prathamesh-sonpatki/rails that referenced this issue Jan 14, 2014
@prathamesh-sonpatki prathamesh-sonpatki Fix fields_for documentation with index option [ci skip]
- fields_for documentation with index option was wrong.
- It does not work with passing model as it is.
- Changed the example by passing id of the address object.
- Fixes #13125.
2cd17a7
@prathamesh-sonpatki prathamesh-sonpatki added a commit to prathamesh-sonpatki/rails that referenced this issue Jan 14, 2014
@prathamesh-sonpatki prathamesh-sonpatki Fix fields_for documentation with index option [ci skip]
- fields_for documentation with index option was wrong.
- It does not work with passing model as it is.
- Changed the example by passing id of the address object.
- Fixes #13125.
3cf5d2b
@senny senny closed this in #13706 Jan 14, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.