# Link\_to\_remote method display a loading image?

**URL:** <https://www.ruby-forum.com/t/link-to-remote-method-display-a-loading-image/97286>\
**Category:** Rails\
**Created:** [July 6, 2006, 3:28am UTC](https://www.ruby-forum.com/t/link-to-remote-method-display-a-loading-image/97286 "2006-07-06T03:28:28Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![d0t1q](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/9e8a1a/32.png) [@d0t1q](https://www.ruby-forum.com/u/d0t1q)\
**Post date:** [July 6, 2006, 3:28am UTC](https://www.ruby-forum.com/t/link-to-remote-method-display-a-loading-image/97286/1 "2006-07-06T03:28:28Z")

</div>

Hey guys,

what would be the best way to incorporate this into the builtin  
link\_to\_remote() method?

document.getElementById(‘main’).innerHTML = ‘’;

Id like for the item above to take place while the page is loading.  
I’m currently doing this with another javascript but would prefer to  
use rails. Unfortunately, rails just sits there until the page loads.

Thank you

---

<div class="post-metadata">

**Author:** ![d0t1q](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/9e8a1a/32.png) [@d0t1q](https://www.ruby-forum.com/u/d0t1q)\
**Post date:** [July 6, 2006, 4:02am UTC](https://www.ruby-forum.com/t/link-to-remote-method-display-a-loading-image/97286/2 "2006-07-06T04:02:06Z")

</div>

i believe link\_to\_remote takes a :before and :after option which you can  
pass js to execute.

mark

---

<div class="post-metadata">

**Author:** ![d0t1q](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/9e8a1a/32.png) [@d0t1q](https://www.ruby-forum.com/u/d0t1q)\
**Post date:** [July 6, 2006, 6:48am UTC](https://www.ruby-forum.com/t/link-to-remote-method-display-a-loading-image/97286/3 "2006-07-06T06:48:09Z")

</div>

I ended up adding a loading() function within prototype.js with this:  
javascript:document.getElementById(‘sleep3’).innerHTML = ‘’;

and adding this to the rhtml:

\<%= link\_to\_remote(“Sleep 3”, :url =\> “/templates/sleep3”, :update =\>  
“test\_div\_01”, :loading =\> “loading(‘test\_div\_01’)” ) %\>

works for me! 🙂 thanks
