views:

44

answers:

3

So I have a rather long controller function that performs various tasks, and it takes around 10-15 seconds. I want to be able to update the user on the status of the function as it goes along (progress bar). Ideally, the function is called as an Ajax request, and would then update the page as it goes along. This would work except you can only update the page once per action. Any ideas? Thank you.

This is what I want to do in code:

def long_function
 updatePage "Starting long_function"
 #some code which take 5 seconds"
 updatePage "Finished with first part"
 #some more code which takes a while
 updatePage "Finished second part"
 #last code part
 updatePage "Finished!"
end
A: 

Maybe you should watch: http://railscasts.com/episodes/217-multistep-forms

Lichtamberg
+3  A: 

maybe something like this: trigger a background task and give it an id that you return. The background task could write messages to the database tagged with that id and you could have another action that lets you long-poll for the messages and thus update the user. The last message will then be the answer.

ormuriauga