Topic: remote_function in Rails 2.3.2

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 <a href="http://craiccomputing.blogspot.com/2009/02/rails-ajax-and-rjs-issue-seeing.html">this</a> 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 it seems like if I'm going to the same controller, that shouldn't matter.  Can you tell me why the text in my definition_box DIV is not changing to "Done!" ???

Re: remote_function in Rails 2.3.2

I would load up firebug, and see if even makes a remote call at all.

Another method which you can take to proceed is to write out the javascript by hand so that it works, and then check to see what the difference between the generated script is, and the working script...

Re: remote_function in Rails 2.3.2

It works now!  Apparently, the issue was resolved when I wrapped the remote call in CDATA tags:


//<![CDATA[
    <%= remote_function(:url => { :action => :lookup } ) %>
//]]>

Re: remote_function in Rails 2.3.2

A slightly prettier solution would be to use javascript_tag:

<%= javascript_tag remote_function(:url => { :action => :lookup } ) %>