我有:
_table中的:
<%= link_to 'Delete', project, remote: true, method: :delete, data: { confirm: 'Sure?' },
class: "btn btn-danger btn-xs" %>
在projects_controller中
def destroy
@project = Project.find(params[:id])
@project.destroy
end
在destroy.js.erb 中
单击“删除”按钮会破坏数据库中的项目,但表行仍保留在表中。可能是什么问题? 下面是生成的html,目标是var element = document.getElementById("project_<%= @project.id %>");
alert("project_<%= @project.id %>"); <--- Here ID is right!
element.parentNode.removeChild(element);
#project_21
:<table id="project-table" class="table-striped"> <thead> <tr>
<th>Название проекта</th>
<th>Описание проекта</th>
<th></th> </tr> </thead>
<tbody>
<tr class="project" id="project_21">
<td>мой</td>
<td></td>
<td>
<a class="btn btn-accept btn-xs" href="/projects/21/edit">Редактировать</a>
<a data-confirm="Вы уверены?" class="btn btn-danger btn-xs" data-remote="true" rel="nofollow" data-method="delete" href="/projects/21">Удалить</a>
</td>
</tr>
</tbody>
</table>