How to show an animated spinner while a background task is processing in nested rails model using aj

Posted by Globalkeith on Stack Overflow See other posts from Stack Overflow or by Globalkeith
Published on 2010-02-02T12:46:19Z Indexed on 2010/05/01 16:07 UTC
Read the original article Hit count: 423

Filed under:
|
|
|

My specific example is highly complex, so I will use the example shown by Ryan from Railscasts to discuss this:

http://railscasts.com/episodes/197-nested-model-form-part-2

Background

I have a form, let's say "Survey", which contains an arbitrary number of "Questions".

Senario

Give i am on the "Edit Survey" page.

I would like to add a button to each "Question" field which calls a remote_function, which in turn queue's up a delayed_job to execute some processing on the "Question".

To give feedback to the user, i would like to disable the button, and show an animated spinner, which remains until the delayed_job has processed the "Question".

Hint - I can add methods to the "Question" model to indicate the status of the delayed_job.

So, with best practices in mind, what is the best way to achieve this?

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about AJAX