A small problem happens to me, more than a problem a bad browsing experience, when I update the record through Ajax, the original record is kept, and the updated one remains as an aggregate, when I should update the same cell, until I update the page the old record disappears, for a better understanding I explain it in 2 images:
In this picture I just edited a file, the table keeps the original record, although temporarily while the page does not load:
When the page is reloaded, the original record disappears and the edited one remains:
I guess it must be the way I updated the file, then I share my code, I hope you can help me:
update.js.erb
<% if @enterprise_tag.errors.empty? %>
$('#exampleModal1').foundation('close');
$("enterprise-<%= @enterprise.id %>").html("<%= escape_javascript(render partial: 'list', locals: { enterprise:@enterprise }) %>");
<% end %>
enterprise_tags_controller.rb
def update
respond_to do |format|
if @enterprise_tag.update(enterprise_tag_params)
format.html { redirect_to admin_dashboard_path, notice: 'enterprise_tag was successfully created.' }
format.js {}
format.json { render json: @enterprise_tag, status: :created, location: @enterprise_tag }
else
format.html { render action: "edit" }
format.json { render json: @enterprise_tag.errors, status: :unprocessable_entity }
end
end
end
link_edit
<%= link_to edit_enterprise_tag_path(enterprise_tag), remote: true, :data => { :open => 'exampleModal1' }, class: "button tiny green" do %><i class="fi-pencil"></i><% end %>
index.html.erb
<table id="enterprise-tags-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>