views:

19

answers:

2

I am combining div toggling with complex forms: http://railscasts.com/episodes/75-complex-forms-part-3

My specific situation: I have a few nested fields being built in table/new.html.erb and Customer/_customer_note_fields. Ordinarily, I would do something like the following to have toggled divs:

# view
<a class="toggle" rel="toggle[expand#<%= note.id %>]">"Click me"</a>

<div class="expand_me" id="<%= "expand#{note.id}" -%>">
"Hello!"
</div>

The problem with the current case is that it is in the middle of a form builder where all the records are new - therefore, they have no IDs! Therefore, there is no unique marker for these divs.

Is there some other unique number belonging to a new unsaved record that I can access? How would you deal with this problem?

A: 

the records don't have ids but the objects themselves do. try calling the id of the object by which I mean the literal ruby object id not object.id

for example:

a = "Just an example"
a.object_id = 39402342

so you can use that as the unique number

Sam
What's the code for that Sam?
sscirrus
I posted code on my answer.
Sam
A: 

Sam's idea would work. Try using note.object_id and see how well it goes. You could also try to create a MD5 or Base64 string based on some data of the object.

Yaraher