Jquery destroy seems to fire twice.
Hi
I get the confirm msgbox "are you sure" twice and have to OK it twice:
<%= button_to 'Remove', line_item, method: :delete, data: {confirm: 'Are you sure?'} %>
In controller:
def destroy
@line_item.destroy
respond_to do |format|
format.html { redirect_to store_index_url(@line_item.cart_id), notice: 'The item was removed from your cart' }
format.json { head :no_content }
end
end
How can I stop this? I have tried a few things that I found on Google without success!!
Thanks
I think the issue is that you're destroying @line_item
but in your redirect_to
you're using @line_item.cart_id
, that doesn't seem right.
Try to store the URL / id / cart you want to redirect to in some variable , and after the destroy use that to redirect_to
.