In my Ruby on Rails application, I am looking to implement a file upload and processing feature. The upload process is usually quick, but the server-side processing can sometimes take more than 20 seconds. In order to provide a better user experience, I want to display a progress indicator instead of a generic 'processing...' message.
I have attempted to use the following code snippet in the view:
<%= periodically_call_remote(:url => {:action => 'progress_monitor', :controller => 'files'},
:frequency => '5',
:update => "setProgress('progressBar','5')"
) %>
The JavaScript function specified in the :update parameter will be executed every 5 seconds.
Furthermore, the files controller contains the following code:
def progress_monitor
render :text => 'whatever'
end
Ultimately, the progress_monitor method should return an integer value representing the current progress (e.g., % complete). This value will then be passed to the 'setProgress' JavaScript function to update a specific on-screen element.
However, I'm encountering difficulties in obtaining the correct response from the server that can be utilized by JavaScript.
If anyone could offer assistance or suggest an alternative approach, it would be greatly appreciated.
For related inquiries, please refer to the updated question link provided here: here.