Loop action and view


#1

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?


#2

Maybe check out http://juggernaut.rubyforge.org/

  • Richard

On Apr 19, 2:40 pm, Nanyang Z. removed_email_address@domain.invalid


#3

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
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

cheers


#4

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?


#5

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.