rek2
2008-May-13 05:49 UTC
Rails+Ajax how to auto update information with out user intervention?
Hi, all the examples I find of ajax on rails are mostly the same, user clicks on link or button and ajax runs.. but what about if ajax starts when the page loads the first time and keeps running? for example to have a clock in reality what I need is to check the number of online users I have in an application and to show this value on the page with out a need to reload.. Any place with a good example on how to do this? or a tip or something? Thanks -- http://rek2.binaryfreedom.info http://www.spboston.org ---------------------------------------------- a social revolution is the only feasible route to the establishment of socialism. - Karl Marx - --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Greg Donald
2008-May-13 05:53 UTC
Re: Rails+Ajax how to auto update information with out user intervention?
On Tue, May 13, 2008 at 12:49 AM, rek2 <rek2-zTjyZANo7oz3ktU1ABlop6HonnlKzd3f@public.gmane.org> wrote:> > Hi, all the examples I find of ajax on rails are mostly the same, > user clicks on link or button and ajax runs.. > but what about if ajax starts when the page loads the first time > and keeps running? for example to have a clock in reality what I need > is to check the number of online users I have in an application and to > show this value on the page with out a need to reload.. > > Any place with a good example on how to do this? or a tip or something? > Thanksperiodically_call_remote http://api.rubyonrails.com/classes/ActionView/Helpers/PrototypeHelper.html#M000959 -- Greg Donald http://destiney.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 -~----------~----~----~----~------~----~------~--~---
rek2
2008-May-13 07:07 UTC
Re: Rails+Ajax how to auto update information with out user intervention?
Greg Donald wrote:> On Tue, May 13, 2008 at 12:49 AM, rek2 <rek2-zTjyZANo7oz3ktU1ABlop6HonnlKzd3f@public.gmane.org> wrote: > >> Hi, all the examples I find of ajax on rails are mostly the same, >> user clicks on link or button and ajax runs.. >> but what about if ajax starts when the page loads the first time >> and keeps running? for example to have a clock in reality what I need >> is to check the number of online users I have in an application and to >> show this value on the page with out a need to reload.. >> >> Any place with a good example on how to do this? or a tip or something? >> Thanks >> > > periodically_call_remote > > http://api.rubyonrails.com/classes/ActionView/Helpers/PrototypeHelper.html#M000959 > > > >Hi thanks for the link.. but there is calling a url I need to call the variable or a method now I have something like this in views: Current online users: <b>1<%= @online %></b> and my method in my controller: class StatusController < ApplicationController def currently_online @online = Status.count_by_sql "SELECT COUNT(*) FROM status WHERE status = ''online'';" end so I have the info I need auto updated on a variable @online -- A Spectre is haunting multinational capitalism--the spectre of free information. All the powers of ``globalism'''' have entered into an unholy alliance to exorcize this spectre: Microsoft and Disney, the World Trade Organization, the United States Congress and the European Commission. Eben Moglen from the FSF. http://emoglen.law.columbia.edu/publications/dcm.html Solidarity: http://www.dailyradical.org http://www.diarioradical.org http://www.spboston.org http://www.binaryfreedom.info --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2008-May-13 08:34 UTC
Re: Rails+Ajax how to auto update information with out user intervention?
On 13 May 2008, at 08:07, rek2 wrote:>> >> >> > Hi thanks for the link.. but there is calling a url I need to call the > variable or a method > now I have something like this in views: > Current online users: <b>1<%= @online %></b> > and my method in my controller: > > class StatusController < ApplicationController > def currently_online > @online = Status.count_by_sql "SELECT COUNT(*) FROM status > WHERE > status = ''online'';" > end > > so I have the info I need auto updated on a variable @onlineFirst off that method probably belongs in the Status class. Secondly I think you''re making this more complicated than it is. All you need is a controller than can generated the appropriae bit of output (ie <b>1< %= @online %></b>). Make sure that that is easily indentifiable in your html (eg <div id="onlineusers">...</div>) then call periodically_update_remote, telling it to update the onlineusers div. 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 -~----------~----~----~----~------~----~------~--~---
rek2
2008-May-13 16:26 UTC
Re: Rails+Ajax how to auto update information with out user intervention?
Frederick Cheung escribió:> On 13 May 2008, at 08:07, rek2 wrote: > >>> >>> >> Hi thanks for the link.. but there is calling a url I need to call the >> variable or a method >> now I have something like this in views: >> Current online users: <b>1<%= @online %></b> >> and my method in my controller: >> >> class StatusController < ApplicationController >> def currently_online >> @online = Status.count_by_sql "SELECT COUNT(*) FROM status >> WHERE >> status = ''online'';" >> end >> >> so I have the info I need auto updated on a variable @online >> > > First off that method probably belongs in the Status class. Secondly I > think you''re making this more complicated than it is. All you need is > a controller than can generated the appropriae bit of output (ie <b>1< > %= @online %></b>). Make sure that that is easily indentifiable in > your html (eg <div id="onlineusers">...</div>) then call > periodically_update_remote, telling it to update the onlineusers div. > > Fred > >Hi Fred, I had it in the status class but then I had a problem because were in the view I have this is in the application layout view, someone told me to put it on this controller and to pass a before filter, that works fine at least as a non-ajax solution. yes yes of course I need to add divisions <div> etc and update that part is clear, but what do I call from periodically_update_remote in the action? the method? or the variable? as you saw before my method does not print anything just puts the right info into a variable. Thanks. . -- http://rek2.binaryfreedom.info http://www.spboston.org ---------------------------------------------- a social revolution is the only feasible route to the establishment of socialism. - Karl Marx - --~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2008-May-13 16:31 UTC
Re: Rails+Ajax how to auto update information with out user intervention?
On 13 May 2008, at 17:26, rek2 wrote:>> >> > > Hi Fred, I had it in the status class but then I had a problem because > were in the view I have this is in the application layout view, > someone > told me to put it on this controller and to pass a before filter, > that > works fine at least as a non-ajax solution.You need to set @online in the controller. What I mean was have a Status.count_online method, which a model thing ( and by the way I''d probably use Status.count :all, :conditions => ["status = ''online''"] rather than count by sql.> > yes yes of course I need to add divisions <div> etc and update that > part is clear, but what do I call from periodically_update_remote in > the action? the method? or the variable? as you saw before my method > does not print anything just puts the right info into a variable.periodically_update_remote makes ajax requests. The only thing it can call is an action (which should output an appropriate bit of html). 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 -~----------~----~----~----~------~----~------~--~---
AndyV
2008-May-14 00:31 UTC
Re: Rails+Ajax how to auto update information with out user intervention?
I remember the dialog. What Fred is suggesting is what was recommended previously. I think the fragmented nature of the conversation jumbled the puzzle but all the pieces were there. On May 13, 12:31 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 13 May 2008, at 17:26, rek2 wrote: > > > Hi Fred, I had it in the status class but then I had a problem because > > were in the view I have this is in the application layout view, > > someone > > told me to put it on this controller and to pass a before filter, > > that > > works fine at least as a non-ajax solution. > > You need to set @online in the controller. What I mean was have a > Status.count_online method, which a model thing ( and by the way I''d > probably use Status.count :all, :conditions => ["status = ''online''"] > rather than count by sql. > > > > > yes yes of course I need to add divisions <div> etc and update that > > part is clear, but what do I call from periodically_update_remote in > > the action? the method? or the variable? as you saw before my method > > does not print anything just puts the right info into a variable. > > periodically_update_remote makes ajax requests. The only thing it can > call is an action (which should output an appropriate bit of html). > > 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 -~----------~----~----~----~------~----~------~--~---