2

I'm trying to delete using AJAX with :remote => true on my link_to

The delete is working fine, getting 200 response, and when page is refreshed item is no longer there.

[30/Jul/2014 11:26:57] "DELETE /credit_cards/12198 HTTP/1.1" 200 - 0.2106

I need it to happen dynamically, when button is clicked the column is removed.

My views, this is located in app/views/spree/checkout/payment

.cc-expiration.two.columns.alpha.omega
        %span.mobile-heading.em

        = link_to (image_tag("icons/delete.png")),
            spree.credit_card_url(card),
            :remote => true, :method => :delete,
            :confirm => 'Are you sure?',
            :class => 'delete_card'

Controller:

def destroy
  @card = Spree::CreditCard.find(params["id"])
  @card.destroy

  respond_to do |format|
    format.html { redirect_to credit_cards_url }
    format.json { head :no_content }
    format.js   { render :layout => false }
  end
end

And finally my destroy.js.erb, located in app/views/spree/credit_cards

$('.delete_card').bind('ajax:success', function() {
        $(this).closest('column').fadeOut();
});

Any help would be greatly appreciated, thank you so much!

1 Answer 1

1

Since you're using the destroy.js.erb, the view file is returned by the ajax response, and executed as such. So you don't need to bind anything to an ajax callback, just execute your code:

// destroy.js.erb
$('.delete_card').closest('column').fadeOut();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.