At the moment of deleting a record with AJAX
, it deletes it but does not update the table with the record removed, possibly maybe it is doing wrong the render
or I need to specify something more to destroy.js
, I share my code, I hope you can help me:
enterprises_controller.rb
def destroy
@enterprise_tag.destroy
respond_to do |format|
if @enterprise_tag.destroy
format.html { redirect_to admin_dashboard_path, notice: "enterprise was remove successfully" }
format.js { render partial: "list" }
end
end
end
destroy.js.erb [I have doubts in this part]
<% if @enterprise_tag.errors.empty? %>
$("#items").append("<%= escape_javascript(render partial: 'list') %>");
<% end %>
index.html.erb
<% if @enterprise_tags.any? %>
<table id="items">
<tbody>
<tr>
<td>Nombre</td>
<td>Fecha de creacion</td>
<td colspan="2">Opciones</td>
</tr>
<% @enterprise_tags.each do |enterprise_tag| %>
<%= render partial: "enterprise_tags/list", locals: { enterprise_tag:enterprise_tag } %>
<% end %>
</tbody>
</table>
<% else %>
<div class="callout small text-center">
<span>No hay ningun registro disponible</span>
</div>
<% end %>
_list.html.erb
<tr>
<td><%= link_to enterprise_tag_path(enterprise_tag), method: :delete, data: { confirm: "¿Desea eliminar este registro?" }, remote: true do %><i class="fi-trash"></i><% end %></td>
</tr>
Browser console
Rails server