Jon Jon - 4 days ago 5
Ajax Question

Refreshing part of a page in rails

Is there an easy way of refreshing part of a page in rails?

Let's say I have a section of the page that is likely to update, say the number of comments on a blog. Is there an easy way of specifying that part of the page (like, the div class it's in or something) and then have that part of the page check to see if there have been any updates in a pre-specified time like say, 30 seconds?

I'm sure this is possible using some wild javascript/ajax/something but does rails have something like this built in?

If not, what would be the best way to go about doing this?

Any help is much appreciated!

Answer

Your best option is to define a partial for the specific section of content that you wish to refresh then render it out in your HTML view. You can also use something like jQuery replace call in your JS view on a similar controller for doing the 'refresh'. Lastly, just add a recurring timer using jQuery that calls for the action of your controller with a JS format.

Comments