fields_for does not work with model :index #13125

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

Comments

Projects
None yet
4 participants
@bughit
Contributor

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

This comment has been minimized.

Show comment
Hide comment
@al2o3cr

al2o3cr Dec 1, 2013

Contributor

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

Contributor

al2o3cr commented Dec 1, 2013

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

@bughit

This comment has been minimized.

Show comment
Hide comment
@bughit

bughit Dec 1, 2013

Contributor

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 %>
Contributor

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

This comment has been minimized.

Show comment
Hide comment
@al2o3cr

al2o3cr Dec 1, 2013

Contributor

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.

Contributor

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

This comment has been minimized.

Show comment
Hide comment
@JonRowe

JonRowe Jan 5, 2014

Contributor

Hey @al2o3cr did you get any further investigating this?

Contributor

JonRowe commented Jan 5, 2014

Hey @al2o3cr did you get any further investigating this?

@al2o3cr

This comment has been minimized.

Show comment
Hide comment
@al2o3cr

al2o3cr Jan 6, 2014

Contributor

@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.

Contributor

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

This comment has been minimized.

Show comment
Hide comment
@JonRowe

JonRowe Jan 6, 2014

Contributor

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

Contributor

JonRowe commented Jan 6, 2014

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

@pixeltrix

This comment has been minimized.

Show comment
Hide comment
@pixeltrix

pixeltrix Jan 6, 2014

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.

Member

pixeltrix commented Jan 6, 2014

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 added a commit to prathamesh-sonpatki/rails that referenced this issue Jan 14, 2014

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.

prathamesh-sonpatki added a commit to prathamesh-sonpatki/rails that referenced this issue Jan 14, 2014

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.

@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