# Ajax call\_remote

**URL:** <https://www.ruby-forum.com/t/ajax-call-remote/132703>\
**Category:** Rails\
**Created:** [March 23, 2008, 7:41pm UTC](https://www.ruby-forum.com/t/ajax-call-remote/132703 "2008-03-23T19:41:20Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![johnlester](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e480ec/32.png) [@johnlester](https://www.ruby-forum.com/u/johnlester)\
**Post date:** [March 23, 2008, 7:41pm UTC](https://www.ruby-forum.com/t/ajax-call-remote/132703/1 "2008-03-23T19:41:20Z")

</div>

Hello, is there something like a “call\_remote” ?

I would like to execute an RJS template after a page is loaded so that  
it sets up the screen’s hidden fields as required when Ajax is in play.

(I don’t want to make certain things hidden by default as I want them to  
show if Javascript is disabled, and I’d prefer not to duplicate code  
client-side that I already have in my rjs files).

Thanks.

---

<div class="post-metadata">

**Author:** ![johnlester](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e480ec/32.png) [@johnlester](https://www.ruby-forum.com/u/johnlester)\
**Post date:** [March 23, 2008, 7:50pm UTC](https://www.ruby-forum.com/t/ajax-call-remote/132703/2 "2008-03-23T19:50:32Z")

</div>

John L. wrote:

> Hello, is there something like a “call\_remote” ?
> 
> I would like to execute an RJS template after a page is loaded so that  
> it sets up the screen’s hidden fields as required when Ajax is in play.

You can add:

\<%= javascript\_tag(remote\_function :url =\> … ) %\>

to the page which will cause it to call the specified action which can  
send back the updates. Is this what you mean?

---

<div class="post-metadata">

**Author:** ![johnlester](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e480ec/32.png) [@johnlester](https://www.ruby-forum.com/u/johnlester)\
**Post date:** [March 23, 2008, 8:29pm UTC](https://www.ruby-forum.com/t/ajax-call-remote/132703/3 "2008-03-23T20:29:04Z")

</div>

Sorted it like this with Javascript:

Event.observe( window, ‘load’, function() {  
\<%= remote\_function :url =\> {:action =\> :display\_fields, :only\_path =\>  
:false}%\>  
} );

Not sure if this is the best way, but it does what I need.

---

<div class="post-metadata">

**Author:** ![johnlester](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e480ec/32.png) [@johnlester](https://www.ruby-forum.com/u/johnlester)\
**Post date:** [March 24, 2008, 1:52pm UTC](https://www.ruby-forum.com/t/ajax-call-remote/132703/4 "2008-03-24T13:52:35Z")

</div>

Mark B. wrote:

> You can add:
> 
> \<%= javascript\_tag(remote\_function :url =\> … ) %\>

Thanks Mark. My solution worked but this is what I actually wanted - I  
just hadn’t thought of it that way. Much more elegant. Thanks!
