I have an application that needs to execute a shell script with quite
a long execution time. I would like to show some “Please wait”-dialog
that can be updated with status from the script. Does anyone have any
ideas of how to do this in Rails.
I have an application that needs to execute a shell script with quite
a long execution time. I would like to show some “Please wait”-dialog
that can be updated with status from the script. Does anyone have any
ideas of how to do this in Rails.
I do something similar in one of my old applications. Mine has a page
of data, some of which loads quickly and is displayed immediately and
some which takes longer. For my app, the user clicks a button to select
which of the longer execution time parts to display, but the principle
is the same.
The long running task is a remote call to:
def prepare_get_details
render :update do |page|
page[“info”].update(“
Preparing details, please wait…
”)
page << remote_function(:url => {:action => :get_details,
‘values[days]’ =>
params[:values][:days],
:update => ‘info’)
end
end
This updates my “info” div with a message (you could display a progress
bar or something if you like). It then adds javascript to the page to
call the long running task and set this to replace the contents of the
same “info” div to replace the “please wait” message. This javascript
is executed when it is received by the browser.
The initial button is displayed on the main page using:
This allows me to reuse the same calls easily in multiple views. You
could utilise other options of remote_function like :loading, etc to do
it all in one call, but I haven’t played extensively with this.
This is simpler than my previous suggestion and more efficient (only 1
call to the server instead of 2). I originally wrote the 2 step approach
to avoid including JavaScript directly (I usually prefer to just call
the Rails helpers - the :before value is JS), but if I was to re-write
it, I’d probably use this method here and create a helper method to wrap
it for re-use.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.