I did and it was not helpful in this case. The problem was that I was
trying to duplicate manually what fields_for does because I needed to
sort the output in a specific way (too long to explain here). Of
course I was not doing a good job. I finally discovered (from a
simpler use of fields_for that I have working) that fields_for
generates actually 2 input tags for each one of the association
records, one for the field you need and another one that is a hidden
field and I believe keeps track of the ID value of the associated
record (not very sure about that, though, I still have to check that
out). Then, as usual, I thought that it was not possible that the
framework didn't have something to take care of my needs and hit the
docs again for the nth time. I paid very close attention this time and
sure enough I found an example that could work with a little bit of a
hack to make my sorting work, and it did.

On Jul 21, 3:42 pm, Colin Law <[email protected]> wrote:
> On 21 July 2010 01:10, pepe <[email protected]> wrote:
>
>
>
> > I have an edit page that generates a few input fields I organized in a
> > table, like so:
> >      <tr>
> >        <td>Driver License</td>
> >        <td>
> >          <input
> > id="person_accounts_attributes_0_account_documents_attributes_1_number"
> > name="person[accounts_attributes][0][account_documents_attributes][1]
> > [number]"  type="text" />
> >        </td>
> >      </tr>
>
> >      <tr>
> >        <td>Passport</td>
> >        <td>
> >          <input
> > id="person_accounts_attributes_0_account_documents_attributes_47_number"
> > name="person[accounts_attributes][0][account_documents_attributes][47]
> > [number]" type="text" value="1" />
> >        </td>
> >      </tr>
>
> >      <tr>
> >        <td>SSN</td>
> >        <td>
> >          <input
> > id="person_accounts_attributes_0_account_documents_attributes_48_number"
> > name="person[accounts_attributes][0][account_documents_attributes][48]
> > [number]" type="text" value="2" />
> >        </td>
> >      </tr>
>
> > The same fields work great in a 'new' page (probably because that page
> > accepts values only once) but if I click on the Submit button of the
> > 'edit' page the fields that have a value generate duplicate records in
> > the DB. The fields that contain no value do not.
>
> > The 'update' action just issues a
> > @person.update_attributes(params[:person]) statement.
>
> > I have been battling this for a long time.
>
> Have you had a look in development.log to get a clue to what is happening?
>
> Colin

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to