我有一个包含对象列表(@contacts)的索引页面,我需要能够使用 ajax 编辑弹出窗口中的每个@contact 条目。对象列表:
<% @contacts.each do |contact| %>
<div><%= contact.name %> | <%= link_to 'Edit', edit_contact_path(contact), :id => "edit_contact_dialog_link_#{contact.id}" %></div>
<% @contact = contact %><%= render :template => "contacts/edit" %>
<% end %>
在这里,我为所有编辑链接添加了一个唯一的 ID。在以下方面做得很好edit.html.erb
:
<div id="edit_contact_dialog_<%= @contact.id %>">
<h1>Editing contact</h1>
<%= render 'form' %>
</div>
现在在索引页面上,我有一个联系人列表(带有唯一的编辑链接edit_contact_dialog_link_ID
)和编辑表单(带有唯一的 div id edit_contact_dialog_ID
)
我需要隐藏所有edit_contact_dialog_ID
框并在每次edit_contact_dialog_link_ID
单击时打开相应的对话框窗口,但不知道如何。
我的contacts.js
:
$("#edit_contact_dialog_(here i need a regexp or smthng?)").dialog({
autoOpen: false,
width: 455,
modal: true
});
$("#edit_contact_dialog_link_???").click(function(){
$("#edit_contact_dialog_???").dialog("open");
return false;
});
谢谢你的帮助。