# How to render :partials \*before\* the :action has finished?

**URL:** <https://www.ruby-forum.com/t/how-to-render-partials-before-the-action-has-finished/162117>\
**Category:** Rails\
**Created:** [March 5, 2009, 10:14pm UTC](https://www.ruby-forum.com/t/how-to-render-partials-before-the-action-has-finished/162117 "2009-03-05T22:14:58Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![tharrisx](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/e19adc/32.png) [@tharrisx](https://www.ruby-forum.com/u/tharrisx)\
**Post date:** [March 5, 2009, 10:14pm UTC](https://www.ruby-forum.com/t/how-to-render-partials-before-the-action-has-finished/162117/1 "2009-03-05T22:14:58Z")

</div>

Hi there,

I’m sure a lot of you guys have come across this question:

How can we render several :partials on a page _before_ the called  
:action has finished?

Basically, my situation is this:

When I click on a certain button, 3 things are supposed to happen:

- INSTANTLY: the button should become disabled (either by setting  
“:disabled” to “true” by updating the partial or by using  
“:disable\_with”)
- INSTANTLY: one or several things should appear on the page (probably  
as :partials)
- “IN THE BACKGROUND”: sending out 2 emails (which takes too much time  
to wait for)

The thing is: it’s impossible to do it like below (since “render” always  
seems to be executed at the end of an :action):

render :update do |page|  
page.replace\_html ‘whateverDiv’, :partial =\> ‘whateverPartial’  
page.replace\_html ‘whateverDiv2’, :partial =\> ‘whateverPartial2’  
end

What’s the easiest/best solution in Rails to solve this problem?

Thanks a lot for your help!  
Tom

---

<div class="post-metadata">

**Author:** ![tharrisx](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/e19adc/32.png) [@tharrisx](https://www.ruby-forum.com/u/tharrisx)\
**Post date:** [March 5, 2009, 10:45pm UTC](https://www.ruby-forum.com/t/how-to-render-partials-before-the-action-has-finished/162117/2 "2009-03-05T22:45:05Z")

</div>

On 5 Mar 2009, at 21:14, Tom Ha wrote:

> When I click on a certain button, 3 things are supposed to happen:  
> seems to be executed at the end of an :action):
> 
> render :update do |page|  
> page.replace\_html ‘whateverDiv’, :partial =\> ‘whateverPartial’  
> page.replace\_html ‘whateverDiv2’, :partial =\> ‘whateverPartial2’  
> end

The response is only send out when fully finished. If you want  
something like this then one option is to push the background task  
into something like backgroundrb or bj (so that the action does finish  
quickly)

Fred

---

<div class="post-metadata">

**Author:** ![tharrisx](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/e19adc/32.png) [@tharrisx](https://www.ruby-forum.com/u/tharrisx)\
**Post date:** [March 5, 2009, 11:08pm UTC](https://www.ruby-forum.com/t/how-to-render-partials-before-the-action-has-finished/162117/3 "2009-03-05T23:08:35Z")

</div>

Tom Ha wrote:

> When I click on a certain button, 3 things are supposed to happen:
> 
> - INSTANTLY: the button should become disabled (either by setting  
> “:disabled” to “true” by updating the partial or by using  
> “:disable\_with”  
> Just add an onclick javascript script event that disables the button -  
> no need for the server to push this back.
> - INSTANTLY: one or several things should appear on the page (probably  
> as :partials)  
> Serve this from your controller as normal.

> - “IN THE BACKGROUND”: sending out 2 emails (which takes too much time  
> to wait for)

Add the emails to be sent to a queue table (instantaneous) and have a  
background process that routinely generates the emails.

---

<div class="post-metadata">

**Author:** ![tharrisx](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/e19adc/32.png) [@tharrisx](https://www.ruby-forum.com/u/tharrisx)\
**Post date:** [March 5, 2009, 11:37pm UTC](https://www.ruby-forum.com/t/how-to-render-partials-before-the-action-has-finished/162117/4 "2009-03-05T23:37:56Z")

</div>

Thanks very much, guys!
