Javascript Polling and Ruby on Rails

Hello,

I am new to Ruby on Rails and sometimes having a real hard time tying everything together...

For my mobile website I have to get the current position (geolocation) of a user every 5 minutes and compare this position and the current time with values of position/time stored in my database. Depending on those values I might have to update another database table and do some javascript alert or update my view.

Unfortunately, I have no idea where to place the code for all this stuff. The periodical check of the geolocation I could do with javascript but how do I query and update the database? In my .js-file as well? I think this is not the best separation of model, view and controller, is it? Is there maybe any way to do those pollings in my controller directly?

Thanks for any help!

You could create your JavaScript method so that it hits the update method in whatever object holds the user's location, and be sure to restrict this to the is_xhr part of things. A regular update would just update the instance, but an xhr update would check if the location had changed first, and return updated if true, and no change if false. And render nothing either way. That way, if you're using the Prototype periodical updater, you can take advantage of the decay feature, which spreads out the time between requests if there's no change.

Walter