Forum: Ruby on Rails Ajax, getting Data from the Database every 5 seconds

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
David S. (Guest)
on 2006-05-03 05:48
Hi,

I want to show 3 products every 5 seconds using AJAX. I want to get 3
random products from the database and show them. How would I go about
doing that?

Thanks

David
Bryan D. (Guest)
on 2006-05-03 17:01
Use a periodic updater - you can find the documentation under
PrototypeHelper at api.rubyonrails.org.

Then, just generate a random number, use it to find a product, and
return an html fragment that displays it. Not too hard.
Christopher W. (Guest)
on 2006-05-03 20:28
Use the following to select a random record from the database in MySQL:

@products = find_by_sql("SELECT * FROM products ORDER BY RAND() LIMIT
3");

That should be the one liner you need.

Bryan D. wrote:
> Use a periodic updater - you can find the documentation under
> PrototypeHelper at api.rubyonrails.org.
>
> Then, just generate a random number, use it to find a product, and
> return an html fragment that displays it. Not too hard.
This topic is locked and can not be replied to.