Hi all, I''m trying to pass more than one parameters using link_to_remote, but I''m getting a behaviour that seems quite strange to me. Here''s the code: link_to_remote ''some text'', :update => ''form'', :method => ''get'', :url => { :action => ''my_action'', :id => @my_object, :extra_param => ''my_extra'' } The URL I got is: ''/controller/my_action/32?extra_param=my_extra'' (32 is @my_object''s id) but params[:extra_param] contains ''my_extra?''. Why that extra question mark? I think I''m missing something. Any idea? Thank you in advance. -- _o) Imobach González Sosa //\ email: imobachgs at step dot es V_/_ jid: osoh at jabberes dot org url: http://www.banot.net/~osoh/ blog: http://devnull.blogs.banot.net -- Este mensaje ha sido analizado por STEP On Line en busca de virus y otros contenidos peligrosos, y se considera que está limpio. 902 10 18 43
On 16.10.2005, at 22.26, Imobach González Sosa wrote:> Hi all, > > I''m trying to pass more than one parameters using link_to_remote, > but I''m > getting a behaviour that seems quite strange to me. Here''s the code: > > link_to_remote ''some text'', > :update => ''form'', > :method => ''get'', > :url => { :action => ''my_action'', :id => > @my_object, :extra_param => ''my_extra'' } > > The URL I got is: ''/controller/my_action/32? > extra_param=my_extra'' (32 is > @my_object''s id) but params[:extra_param] contains ''my_extra?''. Why > that > extra question mark? > > I think I''m missing something. > >You should put all your "extra" parameters in :params hash. So: :url => { :action => ''my_action'', :id => @my_object, :params => {:extra_param => ''my_extra''} } :id is just a short hand method for :params => {:id...} //jarkko> > Any idea? Thank you in advance. > > -- > _o) Imobach González Sosa > //\ email: imobachgs at step dot es > V_/_ jid: osoh at jabberes dot org > url: http://www.banot.net/~osoh/ > blog: http://devnull.blogs.banot.net > > -- > Este mensaje ha sido analizado por STEP On Line > en busca de virus y otros contenidos peligrosos, > y se considera que está limpio. 902 10 18 43 > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > > >-- Jarkko Laine http://jlaine.net http://odesign.fi _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
You get the question mark because that is why how parameters are sent when the method is GET Normally your address would be http://site/controller/my_action?id=32&extra_param=my_extra So your question should be "why is the ''id'' word missing from the link" :-) Bogdan On 10/16/05, Imobach González Sosa <imobachgs-gShqw608wn4@public.gmane.org> wrote:> > Hi all, > > I''m trying to pass more than one parameters using link_to_remote, but I''m > getting a behaviour that seems quite strange to me. Here''s the code: > > link_to_remote ''some text'', > :update => ''form'', > :method => ''get'', > :url => { :action => ''my_action'', :id => > @my_object, :extra_param => ''my_extra'' } > > The URL I got is: ''/controller/my_action/32?extra_param=my_extra'' (32 is > @my_object''s id) but params[:extra_param] contains ''my_extra?''. Why that > extra question mark? > > I think I''m missing something. > > Any idea? Thank you in advance. > > -- > _o) Imobach González Sosa > //\ email: imobachgs at step dot es > V_/_ jid: osoh at jabberes dot org > url: http://www.banot.net/~osoh/ > blog: http://devnull.blogs.banot.net > > -- > Este mensaje ha sido analizado por STEP On Line > en busca de virus y otros contenidos peligrosos, > y se considera que está limpio. 902 10 18 43 > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >_______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Imobach González Sosa
2005-Oct-16 21:00 UTC
Re: More than one parameter with link_to_remote
El Sunday, 16 de October de 2005 20:55, Jarkko Laine escribió:> On 16.10.2005, at 22.26, Imobach González Sosa wrote: > > Hi all, > > > > I''m trying to pass more than one parameters using link_to_remote, > > but I''m > > getting a behaviour that seems quite strange to me. Here''s the code: > > > > link_to_remote ''some text'', > > > > :update => ''form'', > > :method => ''get'', > > :url => { :action => ''my_action'', :id => > > > > @my_object, :extra_param => ''my_extra'' } > > > > The URL I got is: ''/controller/my_action/32? > > extra_param=my_extra'' (32 is > > @my_object''s id) but params[:extra_param] contains ''my_extra?''. Why > > that > > extra question mark? > > > > I think I''m missing something. > > You should put all your "extra" parameters in :params hash. So: > :url => { :action => ''my_action'', :id => > > @my_object, :params => {:extra_param => ''my_extra''} }it didn''t work... same result. It''s late, so I try again tomorrow. Thank you anyway. -- _o) Imobach González Sosa //\ email: imobachgs at banot dot net V_/_ jid: osoh at jabberes dot org url: http://www.banot.net/~osoh/ blog: http://devnull.blogs.banot.net -- Este mensaje ha sido analizado por STEP On Line en busca de virus y otros contenidos peligrosos, y se considera que está limpio. 902 10 18 43
Imobach González Sosa
2005-Oct-16 21:02 UTC
Re: More than one parameter with link_to_remote
El Sunday, 16 de October de 2005 20:56, Bogdan Ionescu escribió: Hi,> You get the question mark because that is why how parameters are sent when > the method is GETYes, I know.> Normally your address would be > http://site/controller/my_action?id=32&extra_param=my_extra > So your question should be "why is the ''id'' word missing from the link" :-)I mean the last question mark. That''s right: ''/controller/my_action/32?extra_param=my_extra'', but params[:extra_param] contains "32?". Thanks anyway. -- _o) Imobach González Sosa //\ email: imobachgs at banot dot net V_/_ jid: osoh at jabberes dot org url: http://www.banot.net/~osoh/ blog: http://devnull.blogs.banot.net -- Este mensaje ha sido analizado por STEP On Line en busca de virus y otros contenidos peligrosos, y se considera que está limpio. 902 10 18 43
Imobach González Sosa wrote:> I mean the last question mark. That''s right: > ''/controller/my_action/32?extra_param=my_extra'', but params[:extra_param] > contains "32?".I think you meant (as in your original post) > params[:extra_param] contains ''my_extra?'' Trying this with Ruby 1.8.2 and Rails 0.13.1 on Windows XP I am not seeing the problem... using a quick modification of the first Ajax example in Chapter 18 of "Agile Web Development with Rails", I have this in the web page: <%= link_to_remote(''Do the Ajax thing'', :update => ''mydiv'', :url => {:action => :ajax_hello, :id => 3, :x => ''foo''}) %> <div id="mydiv">This text will be changed</div> this in the controller: def ajax_hello render(:layout => false) end and this in ajax_hello.rhtml: <pre> params[:controller] = <%=h params[:controller] %> params[:action] = <%=h params[:action] %> params[:id] = <%=h params[:id] %> params[:x] = <%=h params[:x] %> </pre> and the resulting display is: params[:controller] = say params[:action] = ajax_hello params[:id] = 3 params[:x] = foo ...nothing unexpected. regards Justin
Imobach González Sosa
2005-Oct-17 06:55 UTC
Re: More than one parameter with link_to_remote
El Monday, 17 de October de 2005 01:00, Justin Forder escribió:> Imobach González Sosa wrote: > > I mean the last question mark. That''s right: > > ''/controller/my_action/32?extra_param=my_extra'', but params[:extra_param] > > contains "32?". > > I think you meant (as in your original post) > > > params[:extra_param] contains ''my_extra?''Yes, I mean the extra_param value.> Trying this with Ruby 1.8.2 and Rails 0.13.1 on Windows XP I am not > seeing the problem... using a quick modification of the first Ajax > example in Chapter 18 of "Agile Web Development with Rails", I have > this in the web page: > > <%= link_to_remote(''Do the Ajax thing'', > > :update => ''mydiv'', > :url => {:action => :ajax_hello, > : > :id => 3, > :x => ''foo''}) %> > > <div id="mydiv">This text will be changed</div> > > this in the controller: > > def ajax_hello > render(:layout => false) > end > > and this in ajax_hello.rhtml: > > <pre> > params[:controller] = <%=h params[:controller] %> > params[:action] = <%=h params[:action] %> > params[:id] = <%=h params[:id] %> > params[:x] = <%=h params[:x] %> > </pre> > > and the resulting display is: > > params[:controller] = say > params[:action] = ajax_hello > params[:id] = 3 > params[:x] = foo > > ...nothing unexpected.Then I''ll review my code again... Thank you very much for your time ;) -- _o) Imobach González Sosa //\ email: imobachgs at banot dot net V_/_ jid: osoh at jabberes dot org url: http://www.banot.net/~osoh/ blog: http://devnull.blogs.banot.net -- Este mensaje ha sido analizado por STEP On Line en busca de virus y otros contenidos peligrosos, y se considera que está limpio. 902 10 18 43
Imobach González Sosa
2005-Oct-17 07:03 UTC
Re: More than one parameter with link_to_remote
El Monday, 17 de October de 2005 01:00, Justin Forder escribió:> Imobach González Sosa wrote:Sorry, I forgot something.> Trying this with Ruby 1.8.2 and Rails 0.13.1 on Windows XP I am not > seeing the problem... using a quick modification of the first Ajax > example in Chapter 18 of "Agile Web Development with Rails", I have > this in the web page: > > <%= link_to_remote(''Do the Ajax thing'', > :update => ''mydiv'', > :url => {:action => :ajax_hello, > :id => 3, > :x => ''foo''}) %> > <div id="mydiv">This text will be changed</div> > > this in the controller:Could you try that code using the ''get'' method? (:method => ''get'' I think). Thank you again. -- _o) Imobach González Sosa //\ email: imobachgs at banot dot net V_/_ jid: osoh at jabberes dot org url: http://www.banot.net/~osoh/ blog: http://devnull.blogs.banot.net -- Este mensaje ha sido analizado por STEP On Line en busca de virus y otros contenidos peligrosos, y se considera que está limpio. 902 10 18 43
Imobach González Sosa wrote:> El Monday, 17 de October de 2005 01:00, Justin Forder escribió: > >>Imobach González Sosa wrote: > > > Sorry, I forgot something. > > >>Trying this with Ruby 1.8.2 and Rails 0.13.1 on Windows XP I am not >>seeing the problem... using a quick modification of the first Ajax >>example in Chapter 18 of "Agile Web Development with Rails", I have >>this in the web page: >> >> <%= link_to_remote(''Do the Ajax thing'', >> :update => ''mydiv'', >> :url => {:action => :ajax_hello, >> :id => 3, >> :x => ''foo''}) %> >> <div id="mydiv">This text will be changed</div> >> >>this in the controller: > > > Could you try that code using the ''get'' method? (:method => ''get'' I think). > > Thank you again. >Ha! You are right. Sorry to have missed that out before. I see the same problem as you: <%= link_to_remote(''Do the Ajax thing'', :update => ''mydiv'', :method => ''get'', :url => {:action => :ajax_hello, :id => 3, :x => ''foo''}) %> gives params[:controller] = say params[:action] = ajax_hello params[:id] = 3 params[:x] = foo? That *must* be a bug! regards Justin
Justin Forder wrote:> Imobach González Sosa wrote: > >> El Monday, 17 de October de 2005 01:00, Justin Forder escribió: >> >>> Imobach González Sosa wrote: >> >> >> >> Sorry, I forgot something. >> >> >>> Trying this with Ruby 1.8.2 and Rails 0.13.1 on Windows XP I am not >>> seeing the problem... using a quick modification of the first Ajax >>> example in Chapter 18 of "Agile Web Development with Rails", I have >>> this in the web page: >>> >>> <%= link_to_remote(''Do the Ajax thing'', >>> :update => ''mydiv'', >>> :url => {:action => :ajax_hello, >>> :id => 3, >>> :x => ''foo''}) %> >>> <div id="mydiv">This text will be changed</div> >>> >>> this in the controller: >> >> >> >> Could you try that code using the ''get'' method? (:method => ''get'' I >> think). >> >> Thank you again. >> > > Ha! You are right. Sorry to have missed that out before. > I see the same problem as you: > > <%= link_to_remote(''Do the Ajax thing'', > :update => ''mydiv'', > :method => ''get'', > :url => {:action => :ajax_hello, > :id => 3, > :x => ''foo''}) %> > > gives > > params[:controller] = say > params[:action] = ajax_hello > params[:id] = 3 > params[:x] = foo? > > That *must* be a bug! >Following Jarkko''s advice doesn''t change this: <%= link_to_remote(''Do the Ajax thing'', :update => ''mydiv'', :method => ''get'', :url => {:action => :ajax_hello, :id => 3, :params => {:x => ''foo''}}) %> gives params[:controller] = say params[:action] = ajax_hello params[:id] = 3 params[:x] = foo? and View Source on the page containing the AJAX call shows <a href="#" onclick="new Ajax.Updater(''mydiv'', ''/say/ajax_hello/3?x=foo'', {asynchronous:true, evalScripts:true, method:''get''}); return false;">Do the Ajax thing</a> If I take away :method => ''get'', the problem disappears. View Source shows: <a href="#" onclick="new Ajax.Updater(''mydiv'', ''/say/ajax_hello/3?x=foo'', {asynchronous:true, evalScripts:true}); return false;">Do the Ajax thing</a> So maybe the problem is in the Prototype JavaScript code. For now, I suggest you don''t specify :method => ''get'', because it will use GET anyway AFAIK. regards Justin PS Will be offline for ~12 hours now - have to go to work!
imobachgs-gShqw608wn4@public.gmane.org
2005-Oct-17 08:54 UTC
Re: More than one parameter with link_to_remote
Mensaje citado por Justin Forder <justin-zSfPWr5aQuznITO/+xaoB7VCufUGDwFn@public.gmane.org>:> Following Jarkko''s advice doesn''t change this: > > <%= link_to_remote(''Do the Ajax thing'', > :update => ''mydiv'', > :method => ''get'', > :url => {:action => :ajax_hello, > :id => 3, > :params => {:x => ''foo''}}) %> > gives > > params[:controller] = say > params[:action] = ajax_hello > params[:id] = 3 > params[:x] = foo? > > and View Source on the page containing the AJAX call shows > > <a href="#" onclick="new Ajax.Updater(''mydiv'', > ''/say/ajax_hello/3?x=foo'', {asynchronous:true, evalScripts:true, > method:''get''}); return false;">Do the Ajax thing</a> > > If I take away :method => ''get'', the problem disappears. View Source shows: > <a href="#" onclick="new Ajax.Updater(''mydiv'', > ''/say/ajax_hello/3?x=foo'', {asynchronous:true, evalScripts:true}); > return false;">Do the Ajax thing</a> > > So maybe the problem is in the Prototype JavaScript code.Yes, maybe.> For now, I suggest you don''t specify :method => ''get'', because it will > use GET anyway AFAIK.No, AFAIK (I tested it now) it uses ''post method'' by default.> regards > > Justin > > PS Will be offline for ~12 hours now - have to go to work!Thank you for your help. I think I submit the ¿bug?. ------------------- http://www.step.es/ -- Este mensaje ha sido analizado por STEP On Line en busca de virus y otros contenidos peligrosos, y se considera que está limpio. 902 10 18 43
imobachgs-gShqw608wn4@public.gmane.org wrote:> Mensaje citado por Justin Forder <justin-zSfPWr5aQuznITO/+xaoB7VCufUGDwFn@public.gmane.org>: > > >>Following Jarkko''s advice doesn''t change this: >> >> <%= link_to_remote(''Do the Ajax thing'', >> :update => ''mydiv'', >> :method => ''get'', >> :url => {:action => :ajax_hello, >> :id => 3, >> :params => {:x => ''foo''}}) %> >>gives >> >>params[:controller] = say >>params[:action] = ajax_hello >>params[:id] = 3 >>params[:x] = foo? >> >>and View Source on the page containing the AJAX call shows >> >> <a href="#" onclick="new Ajax.Updater(''mydiv'', >>''/say/ajax_hello/3?x=foo'', {asynchronous:true, evalScripts:true, >>method:''get''}); return false;">Do the Ajax thing</a> >> >>If I take away :method => ''get'', the problem disappears. View Source shows: >> <a href="#" onclick="new Ajax.Updater(''mydiv'', >>''/say/ajax_hello/3?x=foo'', {asynchronous:true, evalScripts:true}); >>return false;">Do the Ajax thing</a> >> >>So maybe the problem is in the Prototype JavaScript code. > > > Yes, maybe.Tonight I tested with an HTML file, using the prototype.js library, and targeting a "snoop servlet" which echoes the details of the request. The HTML file contained: <a href="#" onclick="new Ajax.Updater(''mydiv'', ''http://www.mycgiserver.com/servlet/justinforder.Snoop?x=foo'', {asynchronous:true, evalScripts:true, method:''get''}); return false;">Do the Ajax thing</a> and the response was: -----start----- Requested URL: http://www.mycgiserver.com/servlet/justinforder.Snoop Request information: Request method: GET Request URI: /servlet/justinforder.Snoop Request protocol: HTTP/1.1 Servlet path: /servlet/justinforder.Snoop Path info: <none> Path translated: <none> Query string: x=foo? Content length: <none> Content type: <none> Server name: www.mycgiserver.com Server port: 80 Remote user: <none> Remote address: 217.169.11.194 Remote host: 217.169.11.194 Authorization scheme: Basic Request headers: Accept: */* Accept-Language: en-gb x-prototype-version: 1.3.1 Referer: file://C:\Documents and Settings\Justin\My Documents\test-ajax\Hello from Rails and AJAX-get.htm x-requested-with: XMLHttpRequest Accept-Encoding: gzip, deflate User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; Feedreader; .NET CLR 1.1.4322) Host: www.mycgiserver.com Connection: Keep-Alive SCRIPT_URL: /servlet/justinforder.Snoop SCRIPT_URI: http://www.mycgiserver.com/servlet/justinforder.Snoop Servlet parameters (Single Value style): x = foo? Servlet parameters (Multiple Value style): x = foo? -----end-----> > >>For now, I suggest you don''t specify :method => ''get'', because it will >>use GET anyway AFAIK. > > > No, AFAIK (I tested it now) it uses ''post method'' by default.You are right. Doing the same test without method:''get'' in the Ajax.Updater parameters showed that the request method was POST, and gave the correct parameter value x = foo (Strange, though, to use POST with all the parameters in the URL.) So this is really looks like a bug in the AJAX stuff (Prototype/XMLHTTPRequest), rather than a bug in Rails. regards Justin
Hi, On 10/17/05, Justin Forder <justin-zSfPWr5aQuznITO/+xaoB7VCufUGDwFn@public.gmane.org> wrote:> So this is really looks like a bug in the AJAX stuff > (Prototype/XMLHTTPRequest), rather than a bug in Rails.You are right. Please try the 1.4.0_rc1 version at http://dev.conio.net/repos/prototype/dist/prototype.js (also available in Rails SVN trunk). Sam
Imobach González Sosa
2005-Oct-18 07:05 UTC
Re: More than one parameter with link_to_remote
El Tuesday, 18 de October de 2005 06:50, Sam Stephenson escribió:> Hi, > > On 10/17/05, Justin Forder <justin-zSfPWr5aQuznITO/+xaoB7VCufUGDwFn@public.gmane.org> wrote: > > So this is really looks like a bug in the AJAX stuff > > (Prototype/XMLHTTPRequest), rather than a bug in Rails. > > You are right. Please try the 1.4.0_rc1 version at > http://dev.conio.net/repos/prototype/dist/prototype.js (also available > in Rails SVN trunk).It works! It seems to work pretty fine. Thank you all! -- _o) Imobach González Sosa //\ email: imobachgs at banot dot net V_/_ jid: osoh at jabberes dot org url: http://www.banot.net/~osoh/ blog: http://devnull.blogs.banot.net -- Este mensaje ha sido analizado por STEP On Line en busca de virus y otros contenidos peligrosos, y se considera que está limpio. 902 10 18 43