Marnen Laibow-Koser wrote:
> On Aug 19, 1:07�pm, James West <[email protected]>
> wrote:
> [...]
>
> Or you could just increment a counter as you create fields, so that
> you have a serial number to put in your id attributes.
>
Now that has possibilities. I don't know why I didn't think of that.
Probably because I had my head stuck on stateleseness when in fact I'm
not hitting the server at all so that should work and I think it's going
to be the best solution.
> Your earlier response suggests that maybe GUIDs are the wrong thing.
I agree. It seems like overkill when simpler solutions should be
available but I'm grasping at straws.
> If the objects are being dynamically created, then as long as Ruby
> knows about them, even if they haven't been saved to the DB, you can
> at least use the object_id which is guaranteed to be unique...
Unfortuntely object_id is not unique.
I changed the view to do this
<%-list_form_id = "list-form-#{f.object_id}"-%>
<%-edit_form_id = "edit-form-#{f.object_id}"-%>
which is fine for existing records.
It's also fine for the first new record but subsequent new records show
the same object_id as the first new record.
This is the result of inspecting the HTML source (firebug) on my test
data with 3 new records added after making the above change.
You can see that the last 3 all have the same ID
list-form-35646040
<ul>
<input id="user_addresses_attributes_0_id" type="hidden" value="13"
name="user[addresses_attributes][0][id]"/>
<div id="list-form-35574920">
</div>
<div id="edit-form-35574920" style="display: none;">
</div>
<input id="user_addresses_attributes_1_id" type="hidden" value="17"
name="user[addresses_attributes][1][id]"/>
<div id="list-form-35566050">
</div>
<div id="edit-form-35566050" style="display: none;">
</div>
<input id="user_addresses_attributes_2_id" type="hidden" value="18"
name="user[addresses_attributes][2][id]"/>
<div id="list-form-35556290">
</div>
<div id="edit-form-35556290" style="display: none;">
</div>
<input id="user_addresses_attributes_3_id" type="hidden" value="19"
name="user[addresses_attributes][3][id]"/>
<div id="list-form-35545190">
</div>
<div id="edit-form-35545190" style="display: none;">
</div>
<input id="user_addresses_attributes_4_id" type="hidden" value="20"
name="user[addresses_attributes][4][id]"/>
<div id="list-form-35535650">
</div>
<div id="edit-form-35535650" style="display: none;">
</div>
<input id="user_addresses_attributes_5_id" type="hidden" value="21"
name="user[addresses_attributes][5][id]"/>
<div id="list-form-35524420">
</div>
<div id="edit-form-35524420" style="display: none;">
</div>
<input id="user_addresses_attributes_6_id" type="hidden" value="22"
name="user[addresses_attributes][6][id]"/>
<div id="list-form-35515770">
</div>
<div id="edit-form-35515770" style="display: none;">
</div>
<input id="user_addresses_attributes_7_id" type="hidden" value="23"
name="user[addresses_attributes][7][id]"/>
<div id="list-form-35506520">
</div>
<div id="edit-form-35506520" style="display: none;">
</div>
<input id="user_addresses_attributes_8_id" type="hidden" value="24"
name="user[addresses_attributes][8][id]"/>
<div id="list-form-35497950">
</div>
<div id="edit-form-35497950" style="display: none;">
</div>
<input id="user_addresses_attributes_9_id" type="hidden" value="25"
name="user[addresses_attributes][9][id]"/>
<div id="list-form-35489260">
</div>
<div id="edit-form-35489260" style="display: none;">
</div>
<input id="user_addresses_attributes_10_id" type="hidden" value="26"
name="user[addresses_attributes][10][id]"/>
<div id="list-form-35478670">
</div>
<div id="edit-form-35478670" style="display: none;">
</div>
<input id="user_addresses_attributes_11_id" type="hidden" value="31"
name="user[addresses_attributes][11][id]"/>
<div id="list-form-35470130">
</div>
<div id="edit-form-35470130" style="display: none;">
</div>
<div id="list-form-35646040">
<li>
</li>
</div>
<div id="edit-form-35646040" style="display: none;">
</div>
<div id="list-form-35646040">
</div>
<div id="edit-form-35646040" style="display: none;">
</div>
<div id="list-form-35646040">
</div>
<div id="edit-form-35646040" style="display: none;">
</div>
</ul>
>
> Best,
> --
> Marnen Laibow-Koser
> http://www.marnen.org
> [email protected]
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---