# Loop action and view

**URL:** <https://www.ruby-forum.com/t/loop-action-and-view/92489>\
**Category:** Rails\
**Created:** [April 19, 2007, 11:40pm UTC](https://www.ruby-forum.com/t/loop-action-and-view/92489 "2007-04-19T23:40:40Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![xain](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/x/82dd89/32.png) [@xain](https://www.ruby-forum.com/u/xain)\
**Post date:** [April 19, 2007, 11:40pm UTC](https://www.ruby-forum.com/t/loop-action-and-view/92489/1 "2007-04-19T23:40:40Z")

</div>

I want to build a loop action, like:

> def loop\_action  
> @current\_job = 0  
> 100.each { |i| @current\_job = i }  
> end

I want the view to display the @current\_job information in realtime and  
I’d like to have a stop button to stop the loop.

any idea to do this?

---

<div class="post-metadata">

**Author:** ![xain](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/x/82dd89/32.png) [@xain](https://www.ruby-forum.com/u/xain)\
**Post date:** [April 19, 2007, 11:58pm UTC](https://www.ruby-forum.com/t/loop-action-and-view/92489/2 "2007-04-19T23:58:10Z")

</div>

Maybe check out [http://juggernaut.rubyforge.org/](http://juggernaut.rubyforge.org/)

- Richard

On Apr 19, 2:40 pm, Nanyang Z. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![xain](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/x/82dd89/32.png) [@xain](https://www.ruby-forum.com/u/xain)\
**Post date:** [April 20, 2007, 12:03am UTC](https://www.ruby-forum.com/t/loop-action-and-view/92489/3 "2007-04-20T00:03:11Z")

</div>

hi there,  
you should look into the ajax/prototype helpers for this kind of  
problem.  
namely periodically\_call\_remote which lets your view call a remote  
function that returns your @current\_job  
explained here:  
[http://api.rubyonrails.org/classes/ActionView/Helpers/PrototypeHelper.html#M000528](http://api.rubyonrails.org/classes/ActionView/Helpers/PrototypeHelper.html#M000528)  
and remote\_function that would let you call a function that would stop  
whatever it is that´s incrementing @current\_job  
explained here:  
[http://api.rubyonrails.org/classes/ActionView/Helpers/PrototypeHelper.html#M000534](http://api.rubyonrails.org/classes/ActionView/Helpers/PrototypeHelper.html#M000534)

cheers

---

<div class="post-metadata">

**Author:** ![xain](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/x/82dd89/32.png) [@xain](https://www.ruby-forum.com/u/xain)\
**Post date:** [April 20, 2007, 12:27am UTC](https://www.ruby-forum.com/t/loop-action-and-view/92489/4 "2007-04-20T00:27:06Z")

</div>

Thank you for replying.  
Richard, it’s a nice plugin, maybe I’ll use it some day. But it seems  
too funtionful for my current simple app, and by the way, it needs  
flash.

alexander wrote:

> you should look into periodically\_call\_remote remote\_function  
> both of these function will call an action, how can I request an action  
> to act on another action?

---

<div class="post-metadata">

**Author:** ![xain](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/x/82dd89/32.png) [@xain](https://www.ruby-forum.com/u/xain)\
**Post date:** [April 20, 2007, 9:23am UTC](https://www.ruby-forum.com/t/loop-action-and-view/92489/5 "2007-04-20T09:23:12Z")

</div>

How about take the action directly into the view?  
like  
\<%

> for job in @jobs%  
> #codes to display job and do other things…
> 
> end  
> %\>

if this works, a looooong page will be rendered, (Will it be rendered  
when the loop ends or whenever a loop render a display content?)

and still, I have no idea how to stop the loops with a button.
