Skip to main content

Jquery destroy seems to fire twice.

Rails • Asked by Simon P


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
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 }

How can I stop this? I have tried a few things that I found on Google without success!!


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.

Login or Create An Account to join the conversation.

Subscribe to the newsletter

Join 27,623+ developers who get early access to new screencasts, articles, guides, updates, and more.

    By clicking this button, you agree to the GoRails Terms of Service and Privacy Policy.

    More of a social being? We're also on Twitter and YouTube.