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 -

On Tue, May 13, 2008 at 12:49 AM, rek2 [email protected] 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


Greg D.
http://destiney.com/

Greg D. wrote:

Thanks

periodically_call_remote

Peak Obsession

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: 1<%= @online %>
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

On 13 May 2008, at 08:07, rek2 wrote:

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 1<
%= @online %>
). Make sure that that is easily indentifiable in
your html (eg

) then call
periodically_update_remote, telling it to update the onlineusers div.

Fred

Frederick C.
escribió:> On 13 May 2008, at 08:07, rek2 wrote:

def currently_online
a controller than can generated the appropriae bit of output (ie 1<
%= @online %>
). Make sure that that is easily indentifiable in
your html (eg

) 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

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 -

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

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

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 C. [email protected]