David Smit
2006-May-03 01:48 UTC
[Rails] Ajax, getting Data from the Database every 5 seconds
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 -- Posted via http://www.ruby-forum.com/.
Bryan Duxbury
2006-May-03 13:01 UTC
[Rails] Re: Ajax, getting Data from the Database every 5 seconds
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. -- Posted via http://www.ruby-forum.com/.
Christopher Winslett
2006-May-03 16:29 UTC
[Rails] Re: Ajax, getting Data from the Database every 5 seconds
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 Duxbury 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.-- Posted via http://www.ruby-forum.com/.