# News Roll

**URL:** <https://www.ruby-forum.com/t/news-roll/155367>\
**Category:** Rails\
**Created:** [December 11, 2008, 3:53am UTC](https://www.ruby-forum.com/t/news-roll/155367 "2008-12-11T03:53:53Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jaikishan\_J](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/ad7895/32.png) [@Jaikishan\_J](https://www.ruby-forum.com/u/Jaikishan_J)\
**Post date:** [December 11, 2008, 3:53am UTC](https://www.ruby-forum.com/t/news-roll/155367/1 "2008-12-11T03:53:53Z")

</div>

Hello,  
I am making an application in which I have a div where a new news is  
flashed  
after every 5 second or so automatically. By automatically, I mean user  
does  
not send any request to server by clicking on anything. The approach I  
think  
which might work is - for news div, I call a javascript function on  
onload  
event function of the div, which after every 5 second sends an ajax  
request  
to server and update that div with a new content. However, as I  
understand  
that this thing needs to be implemented as a separate thread so that  
rest of  
the components on the webpage remains interactable. Is this the right  
approach to solve this or is there a better way to do it?

–  
Thanks,  
Jaikishan

---

<div class="post-metadata">

**Author:** ![Jaikishan\_J](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/ad7895/32.png) [@Jaikishan\_J](https://www.ruby-forum.com/u/Jaikishan_J)\
**Post date:** [December 11, 2008, 10:01am UTC](https://www.ruby-forum.com/t/news-roll/155367/2 "2008-12-11T10:01:23Z")

</div>

On 11 Dec 2008, at 02:53, Jaikishan J. wrote:

> However, as I understand that this thing needs to be implemented as  
> a separate thread so that rest of the components on the webpage  
> remains interactable.

That’s not true.

Fred

---

<div class="post-metadata">

**Author:** ![Jaikishan\_J](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/ad7895/32.png) [@Jaikishan\_J](https://www.ruby-forum.com/u/Jaikishan_J)\
**Post date:** [December 11, 2008, 10:28am UTC](https://www.ruby-forum.com/t/news-roll/155367/3 "2008-12-11T10:28:59Z")

</div>

Solving the similar problem, I am not sure if my previous approach was  
the  
right way. Another thing I could think of is that my server keeps  
sending  
data to my client side proactively for every 5 seconds. How that can be  
acheived in rails?

On Thu, Dec 11, 2008 at 2:30 PM, Frederick C. \<  
removed\_email\_address@domain.invalid\> wrote:

> Fred
> 
> >

–  
Thanks,  
Jaikishan

---

<div class="post-metadata">

**Author:** ![Jaikishan\_J](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/ad7895/32.png) [@Jaikishan\_J](https://www.ruby-forum.com/u/Jaikishan_J)\
**Post date:** [December 11, 2008, 2:23pm UTC](https://www.ruby-forum.com/t/news-roll/155367/4 "2008-12-11T14:23:34Z")

</div>

Jaikishan,

There’s no such thing in HTTP. The server can only answer client  
requests, not the other way around.

Your 1st approach is correct, except your assumption of needing a  
separate thread. What Fred meant is that exactly that, you don’t need  
a separate thread. Your regular Rails app should be more than capable  
to respond to these AJAX requests.

Cheers, Sazima

---

<div class="post-metadata">

**Author:** ![Jaikishan\_J](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/ad7895/32.png) [@Jaikishan\_J](https://www.ruby-forum.com/u/Jaikishan_J)\
**Post date:** [December 11, 2008, 2:31pm UTC](https://www.ruby-forum.com/t/news-roll/155367/5 "2008-12-11T14:31:47Z")

</div>

On Dec 11, 10:28 am, “Jaikishan J.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Solving the similar problem, I am not sure if my previous approach was the  
> right way. Another thing I could think of is that my server keeps sending  
> data to my client side proactively for every 5 seconds. How that can be  
> acheived in rails?

You can use periodically\_call\_remote:  
[http://api.rubyonrails.org/classes/ActionView/Helpers/PrototypeHelper.html#M001427](http://api.rubyonrails.org/classes/ActionView/Helpers/PrototypeHelper.html#M001427)
