Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6775487
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:54:44+00:00 2026-05-26T15:54:44+00:00

Following code does destroy records as intended, but the callback is inherited from one

  • 0

Following code does destroy records as intended, but the callback is inherited from one modal to the next one. So while a record is properly deleted, Rails keeps looking to delete the formerly deleted ones as well.
I’m using a Twitter Bootstrap modal window, that sits in a Rails view template and is shown when a standard Rails delete method is fired, replacing the regular javascript dialog.

How to clear the callback after it has been fired?

$.rails.allowAction = function(element) {

  var message = element.data('confirm'),
  answer = false, callback;
  if (!message) { return true; }

  if ($.rails.fire(element, 'confirm')) {
    myCustomConfirmBox(message, function() {
     callback = $.rails.fire(element,
       'confirm:complete', [answer]);
     if(callback) {
       var oldAllowAction = $.rails.allowAction;
       $.rails.allowAction = function() { return true; };
       element.trigger('click');
       $.rails.allowAction = oldAllowAction;
     }
    });
  }
  return false;
}

function myCustomConfirmBox(message, callback) {
    $('#dialog-confirm').modal('show');
    $('#dialog-confirm button.primary').click(function(){
        callback();
        $('#dialog-confirm').modal('hide');
    });
}

edit:
Since I’m using the same base modal over and over again for any delete action, the callbacks queue up. So when a delete action has been cancelled before, it will still be triggered on another delete instance of a different object, since the callback is still valid. Bottom line: How to clear the callback queue?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T15:54:45+00:00Added an answer on May 26, 2026 at 3:54 pm

    Turns out it is a bad idea to fiddle with the native delete method/callback for various reasons. My workaround solution is as follows.

    Have a “delete” button in your view, with some JS data values:

    #delete button in view template
    link_to "delete", "#", 
       :class => "delete_post", 
       "data-id" => YOUR_POST_ID, 
       "data-controls-modal" => "YOUR_MODAL_LAYER",
           #more bootstrap options here…
    

    Bootstrap opens the modal window. Inside that, have another “delete” button with “remote” set, so the action will use JS.

    #delete button in modal window
    link_to "delete", post_path(0), 
       :method => :delete, 
       :class => "btn primary closeModal", 
       :remote => true  
    

    CloseModal is another :class for me to know when to close the bootstrap modal window. I’ve put an additional function for that in my application.js.
    Note, the default path has a nil value, we’ll attach the real post ID to be deleted via JS in the next step via the “data-id” param:

    #application.js 
    $('a.delete_post').live('click', function(){
        _target = $(this).data('id');
        $('#YOUR_MODAL_LAYER .primary').attr('href', '/posts/' + _target);
    });
    

    The destroy action in our Posts controller will use JS to render an animation for the deleted post:

    #posts_controller.rb
    def destroy
        @post = Post.find(params[:id])
        @post.destroy
        respond_to do |format|
           # format.html { redirect_to(posts_url) }
           format.js { render :content_type => 'text/javascript' }
        end
    end
    

    Insert here effects as you please. In this example we are simply fading out the deleted post:

    #views/posts/destroy.js    
    $("div#post-<%= params[:id] %>").fadeOut();
    

    Altogether this works really smoothly!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I do this? (The following code does NOT work, but I hope
The following code does not work correctly on Windows (but does on Linux): sock
Following code does NOT work, but it expresses well what I wish to do.
Following code does compile in gcc 4.5 but it is not being compiled in
The following code does not have any errors when run script.py -f filename but
The following code does not compile: public class GenericsTest { public static void main(String[]
The following Code does not compile Dim BasicGroups As String() = New String() {Node1,
The following code does not want to compile. See the included error message. Code:
The following code does not run as rootNode is null when retrieved by name
The following code does not set the comment: string userName = yrtre.etre.423369a9-3e57-42da-934d-dae91f87a1e4; MembershipUser user

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.