Im trying to figure out ajax better! I want to delete a row with an ajax request without the whole page being loaded. The row gets delete but in order to check i have to refresh the page manually. The problem Im having is that after the delete button is clicked the item doesnt get removed without refreshing the page still.
Heres my delete button:
<% current_user.agreements.each do |agreement| %>
<div class="remove-dis">
<div class="requestone" style="border-bottom:solid grey 1px;height:100px;">
<div style="float:left;">
<h>Offers</h>
</div>
<%= link_to view_scribe_request_path(agreement) do %>
<div class="text-center">
<h><%= agreement.title%></h>
</div>
<% end %>
<div style="float:left;">
<h>Views</h>
</div>
<div class="text-center">
<h><%= agreement.description%></h>
</div>
<div>
<%= link_to 'delete', agreement_path(agreement), method: :delete, data: { confirm: 'Are you sure?' }, remote: true, :class => 'delete_request' %>
</div>
</div>
</div>
<% end %>
route is:
resources :agreements
Agreement controller: "holds ajax delete method"
def destroy
@agreement = Agreement.find(params[:id])
@agreement.destroy
respond_to do |format|
format.html { redirect_to my_requests_path }
format.json { head :no_content }
format.js { render :layout => false }
end
end
my destroy.js.erb:
$('.delete_request').bind('ajax:success', function() {
$('.remove-dis').fadeOut();
});
I have made some changes to the js and html to see what happens when i remove within a list. all listed items will be js removed from the page until refresh. How can I capture only the one listed row?.
</div>