Show loading screen when performing a task in Rails 3

If my “create” action takes time to load (due to making an API call and then calculating) , what is the best way to show the user a “loading screen” while this task is running in the background?

+3
source share
1 answer

Write some AJAX magic;) Show the downloadable image upon activation and hide it when the AJAX call is completed. And if you do not want to use AJAX, well, hmm, you can check this:

http://yehudakatz.com/2010/09/07/automatic-flushing-the-rails-3-1-plan/

There is also a pearl that somewhat does this. But I have no experience with this. I would go for the AJAX method =)

EDIT:

, create AJAX jQuery. :

function create() {

    $('#loading_image').show();

    $.ajax({
     type: 'POST',
     url: /* URL to your create action: e.g. '/user/create/' */,
     data: $('form').serialize(),
     success: createSuccessHandler,
     error: createErrorHandler,
     complete: hideLoadingImage
    });

}

function createSuccessHandler(data) {

    alert("User created!")

}

function createErrorHandler(data) {

    alert("It failed, ffs!")

}

function hideLoadingImage() {

    $('#loading_image').hide()

}
+7

Source: https://habr.com/ru/post/1788570/


All Articles