All threads / Jquery destroy seems to fire twice.

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

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.

Join the discussion

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

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

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

    logo Created with Sketch.

    Ruby on Rails tutorials, guides, and screencasts for web developers learning Ruby, Rails, Javascript, Turbolinks, Stimulus.js, Vue.js, and more. Icons by Icons8

    © 2020 GoRails, LLC. All rights reserved.