I'm trying to remove records from my table, however even though it removes them it doesn't update the list with ajax:
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 [ Is something missing here? ]
<% 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>
in this code
you are not actually deleting anything, in fact
append
it is used to add html to your elements, not to delete. One solution could be to add id's to your list tagstr
:then in your
destroy.js.erb
, you could delete the specific tag based on its id: