Ask A Question

Notifications

You’re not receiving notifications from this thread.

Jquery destroy seems to fire twice.

Simon P asked in Rails

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

Reply

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.

Reply
Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 87,563+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.