# Can't get remote\_function working on rails 2.3.2

**URL:** <https://www.ruby-forum.com/t/cant-get-remote-function-working-on-rails-2-3-2/170853>\
**Category:** Rails\
**Created:** [June 23, 2009, 5:19pm UTC](https://www.ruby-forum.com/t/cant-get-remote-function-working-on-rails-2-3-2/170853 "2009-06-23T17:19:21Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![naijaguy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/9e8a1a/32.png) [@naijaguy](https://www.ruby-forum.com/u/naijaguy)\
**Post date:** [June 23, 2009, 5:19pm UTC](https://www.ruby-forum.com/t/cant-get-remote-function-working-on-rails-2-3-2/170853/1 "2009-06-23T17:19:21Z")

</div>

I’ve tried moving the code around in different ways, but so far I  
haven’t gotten remote\_function to work for me (I’m using Rails 2.3.2 on  
my Mac). I want to make an AJAX call when I double-click a word on my  
page, and the Javascript function is being called when the ondblclick  
event is fired, but nothing happens when it gets to my the “new  
Ajax.Request” part of my function. The Rails console doesn’t even show  
it as making a call to my controller.

There is a DIV called “definition\_box”, so my remote\_function call used  
to read like this:

\<%= remote\_function(:update =\> “definition\_box”, :url =\> { :action =\>  
:lookup } ) %\>

Then I read this  
and took that out since supposedly it might be duplicating the reference  
to the DIV (here in the view and in the controller), so now it looks  
like this:

\<%= remote\_function(:url =\> { :action =\> :lookup } ) %\>

As you can see, I’m not even trying to pass the Javascript parameter to  
remote\_function at the moment. My Javascript function looks like the  
following and does show me the alert box:

function lookupWord(t) {

alert(‘moving forward’);

\<%= remote\_function(:update =\> “definition\_box”, :url =\> { :action =\>  
:lookup } ) %\>

}

This is what I currently have in my controller:

class HomeController \< ApplicationController  
def index  
end

def lookup()  
logger.debug(‘here’)  
render :update do |page|  
page.replace\_html ‘definition\_box’, ‘Done!’  
end  
end  
end

There used to be a new line in my routes.rb, but I think if I’m going to  
the same controller, that doesn’t change anything, so I commented it  
out. Can you tell me why the text in my definition\_box DIV is not  
changing to “Done!” ???

---

<div class="post-metadata">

**Author:** ![naijaguy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/9e8a1a/32.png) [@naijaguy](https://www.ruby-forum.com/u/naijaguy)\
**Post date:** [June 24, 2009, 3:26pm UTC](https://www.ruby-forum.com/t/cant-get-remote-function-working-on-rails-2-3-2/170853/2 "2009-06-24T15:26:32Z")

</div>

Hi,

I’m using rails 2.3.2 with jrails/jquery and remote\_function works.

Do you have enclosed the remote\_function call with

Hope this helps !

---

<div class="post-metadata">

**Author:** ![naijaguy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/9e8a1a/32.png) [@naijaguy](https://www.ruby-forum.com/u/naijaguy)\
**Post date:** [June 24, 2009, 4:16pm UTC](https://www.ruby-forum.com/t/cant-get-remote-function-working-on-rails-2-3-2/170853/3 "2009-06-24T16:16:39Z")

</div>

Yes, it’s in a script tag that’s up in my node. So just now I  
added this line to my routes.rb wondering if it’s related to the issue:

map.connect ‘lookup’, :controller =\> ‘home’, :action =\> ‘lookup’

Both before and after adding this line, my Javascript alert box pops up  
to let me know it entered the Javascript function that calls my  
remote\_function, but then my debug statement in the controller action  
never spits out anything to the server console!

Thanks for any help…

Gianluca T. wrote:

> Hi,
> 
> I’m using rails 2.3.2 with jrails/jquery and remote\_function works.
> 
> Do you have enclosed the remote\_function call with
> 
> Hope this helps !

---

<div class="post-metadata">

**Author:** ![naijaguy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/9e8a1a/32.png) [@naijaguy](https://www.ruby-forum.com/u/naijaguy)\
**Post date:** [June 24, 2009, 6:20pm UTC](https://www.ruby-forum.com/t/cant-get-remote-function-working-on-rails-2-3-2/170853/4 "2009-06-24T18:20:13Z")

</div>

On 24 Jun 2009, at 15:16, Naija G. wrote:

> remote\_function, but then my debug statement in the controller action  
> never spits out anything to the server console!

You should enclose your code in a CDATA section (

> <https://stackoverflow.com/questions/66837/when-is-a-cdata-section-necessary-within-a-script-tag>

).

Fred

---

<div class="post-metadata">

**Author:** ![naijaguy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/9e8a1a/32.png) [@naijaguy](https://www.ruby-forum.com/u/naijaguy)\
**Post date:** [June 24, 2009, 6:40pm UTC](https://www.ruby-forum.com/t/cant-get-remote-function-working-on-rails-2-3-2/170853/5 "2009-06-24T18:40:14Z")

</div>

I changed the node to this, but it’s still not reaching my lookup  
action in the controller:

```
  <script type="text/javascript" 

```

src=“javascripts/prototype.js”\>

Frederick C. wrote:

> On 24 Jun 2009, at 15:16, Naija G. wrote:
> 
> > remote\_function, but then my debug statement in the controller action  
> > never spits out anything to the server console!
> 
> You should enclose your code in a CDATA section (  
> [javascript - When is a CDATA section necessary within a script tag? - Stack Overflow](http://stackoverflow.com/questions/66837/javascript-cdata-tags)  
> ).
> 
> Fred

---

<div class="post-metadata">

**Author:** ![naijaguy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/9e8a1a/32.png) [@naijaguy](https://www.ruby-forum.com/u/naijaguy)\
**Post date:** [June 24, 2009, 7:36pm UTC](https://www.ruby-forum.com/t/cant-get-remote-function-working-on-rails-2-3-2/170853/6 "2009-06-24T19:36:29Z")

</div>

That worked! So now my DIV text gets changed to this for some reason:

try { Element.update(“definition\_box”, “Done!”); } catch (e) {  
alert(‘RJS error:\n\n’ + e.toString());  
alert(‘Element.update(“definition\_box”, “Done!”);’); throw e }

Gianluca T. wrote:

> Wait a moment,
> 
> I put the javascript tag and remote function not intyo head but just  
> after my div, so I’m sure that is all right with the DOM…
> 
> are you sure you have inserted the correct javascript link tag into head  
> ?
> 
> \<%= javascript\_include\_tag :defaults %\>

---

<div class="post-metadata">

**Author:** ![naijaguy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/9e8a1a/32.png) [@naijaguy](https://www.ruby-forum.com/u/naijaguy)\
**Post date:** [June 24, 2009, 6:46pm UTC](https://www.ruby-forum.com/t/cant-get-remote-function-working-on-rails-2-3-2/170853/7 "2009-06-24T18:46:04Z")

</div>

Wait a moment,

I put the javascript tag and remote function not intyo head but just  
after my div, so I’m sure that is all right with the DOM…

are you sure you have inserted the correct javascript link tag into head  
?

\<%= javascript\_include\_tag :defaults %\>

---

<div class="post-metadata">

**Author:** ![naijaguy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/9e8a1a/32.png) [@naijaguy](https://www.ruby-forum.com/u/naijaguy)\
**Post date:** [June 25, 2009, 2:08am UTC](https://www.ruby-forum.com/t/cant-get-remote-function-working-on-rails-2-3-2/170853/8 "2009-06-25T02:08:09Z")

</div>

Oh, I got it. I needed to change it to this in the view:

// { :action =\> :lookup } ) %\> //]]\>

I remember reading elsewhere that for some reason, having the update  
part in both the view and the controller was redundant and caused an  
exception like that.

Thanks so much!

Naija G. wrote:

> That worked! So now my DIV text gets changed to this for some reason:
> 
> try { Element.update(“definition\_box”, “Done!”); } catch (e) {  
> alert(‘RJS error:\n\n’ + e.toString());  
> alert(‘Element.update(“definition\_box”, “Done!”);’); throw e }
> 
> Gianluca T. wrote:
> 
> > Wait a moment,
> > 
> > I put the javascript tag and remote function not intyo head but just  
> > after my div, so I’m sure that is all right with the DOM…
> > 
> > are you sure you have inserted the correct javascript link tag into head  
> > ?
> > 
> > \<%= javascript\_include\_tag :defaults %\>
