# Rails Order of Execution

**URL:** <https://www.ruby-forum.com/t/rails-order-of-execution/81358>\
**Category:** Rails\
**Created:** [January 8, 2007, 9:15am UTC](https://www.ruby-forum.com/t/rails-order-of-execution/81358 "2007-01-08T09:15:59Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Xeph](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/x/f9ae1b/32.png) [@Xeph](https://www.ruby-forum.com/u/Xeph)\
**Post date:** [January 8, 2007, 9:15am UTC](https://www.ruby-forum.com/t/rails-order-of-execution/81358/1 "2007-01-08T09:15:59Z")

</div>

Hi

I have an RJS file that has scriptaculous page calls and system()  
function calls. They’re in the order of system(), scriptaculous,  
system(), system(), scriptaculous. It seems that all the system()  
functions get executed first, then the scriptaculous effects. Is there  
anyway to have my code get executed in the original order? For example,  
the first system call stops a recording, and first scriptaculous call  
displays a “saving”

 tag; the other two system() tag saves the  
recording, and the final scriptaculous call displays a “recording  
completed” 
 tag.

Any help is appreciated  
Xeph

---

<div class="post-metadata">

**Author:** ![Xeph](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/x/f9ae1b/32.png) [@Xeph](https://www.ruby-forum.com/u/Xeph)\
**Post date:** [January 8, 2007, 12:49pm UTC](https://www.ruby-forum.com/t/rails-order-of-execution/81358/2 "2007-01-08T12:49:24Z")

</div>

The scriptaculous calls merely generate JavaScript that will eventually  
be  
sent to the client. Your RJS file is executed and rendered by the  
server,  
all your system() calls will happen now, and the JavaScript required to  
produce the effects on the frontend will have been generated – _not_  
executed. The generated code is then sent to the client (your browser)  
where  
it is then executed and you see the fancy effects.

You’ll need to perform some ajax calls from the frontend that respond  
with  
RJS to trigger the system() calls on the server. You’ll need one ajax  
call  
per system() call (unless you group them up) which will obviously take  
quite  
a while with any more just a couple of remote calls. Not to mention that  
you’ll need to keep and eye out for clients that don’t perform the full  
number of requests that you’d expect.

My advice is to keep your design as simple as possible, it sounds like  
you’re going to end up with a lot of complex code just for the benefit  
of  
having effects fire in “real” time.
