当这些 div 是新的时切换多个 div(无 ID)
我将 div 切换与复杂形式结合起来: http://railscasts.com/episodes/ 75-complex-forms-part-3
我的具体情况:我在 table/new.html.erb
和 Customer/_customer_note_fields
中构建了一些嵌套字段>。通常,我会执行类似以下操作来切换 div:
# view
<a class="toggle" rel="toggle[expand#<%= note.id %>]">"Click me"</a>
<div class="expand_me" id="<%= "expand#{note.id}" -%>">
"Hello!"
</div>
当前情况的问题是它位于表单生成器的中间,其中所有记录都是新的 - 因此,它们没有 ID!因此,这些 div 没有唯一的标记。
我可以访问属于新的未保存记录的其他唯一编号吗?你会如何处理这个问题?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
记录没有 id,但对象本身有。尝试调用对象的 id,我的意思是文字 ruby 对象 id,而不是 object.id
例如:
所以你可以使用它作为唯一编号
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:
so you can use that as the unique number
萨姆的想法可行。尝试使用 note.object_id 并看看效果如何。您还可以尝试根据对象的某些数据创建 MD5 或 Base64 字符串。
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.