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 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!" ??? -- Posted via http://www.ruby-forum.com/.
Gianluca Tessarolo
2009-Jun-24 13:25 UTC
Re: can''t get remote_function working on rails 2.3.2
Hi, I''m using rails 2.3.2 with jrails/jquery and remote_function works. Do you have enclosed the remote_function call with <script> tag ? Try this... <script language="javascript"> <%= remote_function(:update => "definition_box", :url => { :action => :lookup } ) %> </script> Hope this helps !> 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 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!" ??? >
Yes, it''s in a script tag that''s up in my <head> 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 Tessarolo 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 <script> tag ? > > Try this... > > <script language="javascript"> > <%= remote_function(:update => "definition_box", :url => { :action => > :lookup } ) %> > </script> > > Hope this helps !-- Posted via http://www.ruby-forum.com/.
Frederick Cheung
2009-Jun-24 16:19 UTC
Re: can''t get remote_function working on rails 2.3.2
On 24 Jun 2009, at 15:16, Naija Guy wrote:> > Yes, it''s in a script tag that''s up in my <head> 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! >You should enclose your code in a CDATA section ( http://stackoverflow.com/questions/66837/javascript-cdata-tags ). Fred> Thanks for any help... > > > > Gianluca Tessarolo 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 <script> tag ? >> >> Try this... >> >> <script language="javascript"> >> <%= remote_function(:update => "definition_box", :url => { :action >> => >> :lookup } ) %> >> </script> >> >> Hope this helps ! > > -- > Posted via http://www.ruby-forum.com/. > > >
I changed the <head> node to this, but it''s still not reaching my lookup action in the controller: <head> <script type="text/javascript" src="javascripts/prototype.js"></script> <script type="text/javascript" src="javascripts/effects.js"></script> <script type="text/javascript"> //<![CDATA[ //don''t forget to add <body ondblclick="dictionary()"> function dictionary() { var t = document.getSelection(); //alert(t); od(t); } function od(t) { //t=t.replace(/[!.:?,;"]/, ''''); //while (t.substr(t.length-1,1)=='' '') // t=t.substr(0,t.length-1); //while (t.substr(0,1)=='' '') // t=t.substr(1); //alert(t); if (t) { alert(''moving forward''); <%= remote_function(:update => "definition_box", :url => { :action => :lookup } ) %> } } //]]> </script> </head> Frederick Cheung wrote:> On 24 Jun 2009, at 15:16, Naija Guy 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 ( > http://stackoverflow.com/questions/66837/javascript-cdata-tags > ). > > Fred-- Posted via http://www.ruby-forum.com/.
Gianluca Tessarolo
2009-Jun-24 16:45 UTC
Re: can''t get remote_function working on rails 2.3.2
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... <div id="definition_box"></div> <script language="javascript"> <%= remote_function(:update => "definition_box", :url => { :action => :lookup } ) %> </script> are you sure you have inserted the correct javascript link tag into head ? <%= javascript_include_tag :defaults %>> Yes, it''s in a script tag that''s up in my <head> 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 Tessarolo 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 <script> tag ? >> >> Try this... >> >> <script language="javascript"> >> <%= remote_function(:update => "definition_box", :url => { :action => >> :lookup } ) %> >> </script> >> >> Hope this helps ! >> > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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 Tessarolo 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... > > <div id="definition_box"></div> > <script language="javascript"> > <%= remote_function(:update => "definition_box", :url => { :action => > :lookup } ) %> > </script> > > are you sure you have inserted the correct javascript link tag into head > ? > > <%= javascript_include_tag :defaults %>-- Posted via http://www.ruby-forum.com/.
Oh, I got it. I needed to change it to this in the view: //<![CDATA[ <%= remote_function(:url => { :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 Guy 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 Tessarolo 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... >> >> <div id="definition_box"></div> >> <script language="javascript"> >> <%= remote_function(:update => "definition_box", :url => { :action => >> :lookup } ) %> >> </script> >> >> are you sure you have inserted the correct javascript link tag into head >> ? >> >> <%= javascript_include_tag :defaults %>-- Posted via http://www.ruby-forum.com/.