Hi everyone 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. Kindest regards Erik Lindblad --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Erik Lindblad wrote:> 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("<h2>Preparing details, please wait...</h2>") 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: <div id="info"> <%= button_to_function "Show Details...", remote_function(:url => {:action => :prepare_get_details, ''values[days]'' => params[:values][:days]}) %> </div> 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. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Excellent I have not used render :update but it seems to be what I am looking for. Many, many thanks. Regards Erik Lindblad On 12 Mar, 13:15, Mark Bush <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Erik Lindblad wrote: > > 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("<h2>Preparing details, please wait...</h2>") > 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: > <div id="info"> > <%= button_to_function "Show Details...", > remote_function(:url => {:action => :prepare_get_details, > ''values[days]'' => > params[:values][:days]}) %> > </div> > > 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. > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Erik Lindblad wrote:> I have not used render :update but it seems to be what I am looking > for. Many, many thanks.Note also that you can do it all in one go with something like: <div id="info"> <%= link_to_remote "Show Details...", :update => ''info'', :url => {:action => :get_details}, :before => "$(''info'').update(''Please wait...'')" %> </div> 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. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---