Hello, I was wondering if it was possible to do this... I have a really long task that is written in the controller. I''d like to update the user viewing the webpage by printing out things like "initializing..." then after it completes something printing "completed blah blah" or whatever. I guess the best way to say this is, could I refresh the view from the controller? Thanks, - Jeff Miller -- 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 -~----------~----~----~----~------~----~------~--~---
On 10 Apr 2008, at 22:58, Jeff Miller wrote:> > Hello, > I was wondering if it was possible to do this... I have a really long > task that is written in the controller. I''d like to update the user > viewing the webpage by printing out things like "initializing..." then > after it completes something printing "completed blah blah" or > whatever. > I guess the best way to say this is, could I refresh the view from the > controller?Some sort of PeriodicalUpdater ? (see the periodically_call_remote helper) Fred --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
I''m pretty sure you can only send one response per request. The way I''d do this is to start the processing using something like backgroundrb and then use ajax to make periodic calls to the server saying "is it done yet?". On Apr 11, 10:03 am, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 10 Apr 2008, at 22:58, Jeff Miller wrote: > > > > > Hello, > > I was wondering if it was possible to do this... I have a really long > > task that is written in the controller. I''d like to update the user > > viewing the webpage by printing out things like "initializing..." then > > after it completes something printing "completed blah blah" or > > whatever. > > I guess the best way to say this is, could I refresh the view from the > > controller? > > Some sort of PeriodicalUpdater ? (see the periodically_call_remote > helper) > > Fred--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
hmmm... I can''t seem to find any good information or examples using periodically_call_remote and I have absolutely zero experience with Ajax... I have an idea, though - is there a way to open a popup window and tell it to refresh from the controller or load another page into the popup from the controller? -- 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 -~----------~----~----~----~------~----~------~--~---
No, you can still only send one response per request. From what you
are saying you want to send responses to the browser while the server
is working? I don''t *think* you can do this.
I think you''re either going to need to look into ajax (in particular
XMLHttpRequest), or wait till the server finishes it''s job, and can
return the complete output in one go.
I don''t think there is a helper method for an XMLHttpRequest, but
it''s
not too difficult to understand. For a similar problem in my app, I
did this:
# javascript function
function poll_server(id) {
new Ajax.Request(''<%= url_for :action => :check_processing
%>/'' +
id, {asynchronous:true});
}
- I would call poll_server after the page had loaded.
- The "check_processing" method either returned a result, or some
javascript that would wait 5 seconds, then check processing again:
check_processing.rjs
===========================================
# ruby/rails rjs template
if @finished_processing
# do something cool
else
page.delay( 5 ) do
page << "poll_server( ''#{params[:id]}'' );"
end
end
On Fri, Apr 11, 2008 at 12:03 PM, Jeff Miller
<rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>
wrote:>
> hmmm... I can''t seem to find any good information or examples
using
> periodically_call_remote and I have absolutely zero experience with
> Ajax... I have an idea, though - is there a way to open a popup window
> and tell it to refresh from the controller or load another page into the
> popup from the controller?
> --
> Posted via http://www.ruby-forum.com/.
>
> >
>
--
Jonathan
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---
thanks, I''ll look into 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 -~----------~----~----~----~------~----~------~--~---
Yes, you can do this with ajax. Or, if you just want something simple to work: http://www.html-reference.com/META_httpequiv_refresh.htm -Danimal P.S. Since the request-response pair is single-threaded, you can''t just "poll" it unless the initial request to the controller causes it to be passed off to a background process or another thread or something like that. Otherwise, the initial response back from the controller to the view will "block" until the controller is done. But if you pass of the heavy task to a background process (i.e backgroundrb or something like that) then have another action like "status" that the browser can periodically "poll", then you could use AJAX or the EQUIV-REFRESH on that status. On Apr 10, 6:29 pm, Jeff Miller <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> thanks, I''ll look into 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 -~----------~----~----~----~------~----~------~--~---