Hope I''m not to far off base here - I want a link that will first go the controller, test for javascript and then re-direct to either ajax or non-ajax page. I have the controller code set up but a bit unsure about the link itself Do I need to use a link_to_remote link to get the user over to the controller /action and if.request.xhr? or should just a link_to work. I ask because a link_to doesn''t seem to mean anything , js is turned on and still wind up at the non-ajax form. Stuart -- http://en.wikipedia.org/wiki/Dark_ambient --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
richard.johansson-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2006-Oct-17 11:48 UTC
Re: if.request.xhr?
Hi, If your using the normal link_to helper, your link wont use a xmlhttprequest-object to send the request, but a normal get/post request. Link_to_remote uses the prototype javascript library to send an ajax-request and you will be able to recognize the request as ajax in your controller. Richard --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On 10/17/06, richard.johansson-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org <richard.johansson-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > Hi, > > If your using the normal link_to helper, your link wont use a > xmlhttprequest-object to send the request, but a normal get/post > request. Link_to_remote uses the prototype javascript library to send > an ajax-request and you will be able to recognize the request as ajax > in your controller. > > RichardOkay, that''s what I thought. However , the link isn''t working , meaning right now when I place the mouse over the link it says /mydomain/# I have this in the html doc: <head> <%= javascript_include_tag "prototype" %> And have composed the link as such (though I''ve tried a few different variations) <%= link_to_remote ''Search'', {:url => { :action => ''failover'' }} %> Shouldn''t that create the link ? Thank you Stuart -- http://en.wikipedia.org/wiki/Dark_ambient --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Bump :) On 10/17/06, Dark Ambient <sambient-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > On 10/17/06, richard.johansson-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org <richard.johansson-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: > > > > > > Hi, > > > > If your using the normal link_to helper, your link wont use a > > xmlhttprequest-object to send the request, but a normal get/post > > request. Link_to_remote uses the prototype javascript library to send > > an ajax-request and you will be able to recognize the request as ajax > > in your controller. > > > > Richard > > > Okay, that''s what I thought. However , the link isn''t working , meaning > right now when I place the mouse over the link it says /mydomain/# > > I have this in the html doc: > <head> > <%= javascript_include_tag "prototype" %> > > And have composed the link as such (though I''ve tried a few different > variations) > <%= link_to_remote ''Search'', {:url => { :action => ''failover'' }} %> > > Shouldn''t that create the link ? >Maybe I''m way off base here. I am looking at a codecite presentation. I''ve set up my controller action as such: def failover if request.xhr? redirect_to :controller => ''ajaxsearch'', :action => ''index'' else redirect_to :controller => ''searches'', :action => ''new'' -- http://en.wikipedia.org/wiki/Dark_ambient --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Dark Ambient <sambient@...> writes:> Okay, that''s what I thought. However , the link isn''t working , meaning > right now when I place the mouse over the link it says /mydomain/#That''s because the link is called with Javascript and coded into a JS function call, whereas the status bar only shows the value of the link''s href attribute. View Source and you''ll see an onclick which actually calls the remote call. The <a> itself never actually gets activated, it''s disabled by the javascript in the <a>s onclick. If you want, you can supply a URL to be called if people have javascript switched off, by adding an :href to the link_to_remote: <%= link_to_remote "Text", {:controller => blah, :action => blah}, {:href => url_for(:controller => blah2, :action => blah3)} This will allow non-javascript users to access your site and possibly get the information they would have gotten, at the cost of a full page request. That''s not an automatic thing thought, your code has to be able to deal with both requests Gareth --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On 10/17/06, Gareth Adams <gareth.adams-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > Dark Ambient <sambient@...> writes: > > > Okay, that''s what I thought. However , the link isn''t working , meaning > > right now when I place the mouse over the link it says /mydomain/# > > That''s because the link is called with Javascript and coded into a JS > function > call, whereas the status bar only shows the value of the link''s href > attribute. > View Source and you''ll see an onclick which actually calls the remote > call. > > The <a> itself never actually gets activated, it''s disabled by the > javascript in > the <a>s onclick. > > If you want, you can supply a URL to be called if people have javascript > switched off, by adding an :href to the link_to_remote: > > <%= link_to_remote "Text", {:controller => blah, :action => blah}, {:href > => > url_for(:controller => blah2, :action => blah3)} > > This will allow non-javascript users to access your site and possibly get > the > information they would have gotten, at the cost of a full page request. > That''s > not an automatic thing thought, your code has to be able to deal with both > requests > > GarethThanks Gareth. Unfortunately then something is going wrong here. I created the link_to_remote - <%= link_to_remote "Search for jobs", {:controller => ''ajaxsearch'', :action => ''search''}, {:href => url_for(:controller => ''searches'', :action => ''new'')}%> I believe that is right. With javascript turned on the link does nothing. With js off, I get taken to the right place. Page source : <a href="/searches/new" onclick="new Ajax.Request('''', {asynchronous:true, evalScripts:true}); return false;">Search for jobs</a> Am I totally lame and missing something or is something weird going on ? Stuart --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On 10/17/06, Dark Ambient <sambient-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > > On 10/17/06, Gareth Adams <gareth.adams-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > Dark Ambient <sambient@...> writes: > > > > > Okay, that''s what I thought. However , the link isn''t working , > > meaning > > > right now when I place the mouse over the link it says /mydomain/# > > > > That''s because the link is called with Javascript and coded into a JS > > function > > call, whereas the status bar only shows the value of the link''s href > > attribute. > > View Source and you''ll see an onclick which actually calls the remote > > call. > > > > The <a> itself never actually gets activated, it''s disabled by the > > javascript in > > the <a>s onclick. > > > > If you want, you can supply a URL to be called if people have javascript > > switched off, by adding an :href to the link_to_remote: > > > > <%= link_to_remote "Text", {:controller => blah, :action => blah}, > > {:href => > > url_for(:controller => blah2, :action => blah3)} > > > > This will allow non-javascript users to access your site and possibly > > get the > > information they would have gotten, at the cost of a full page request. > > That''s > > not an automatic thing thought, your code has to be able to deal with > > both > > requests > > > > Gareth > > > Thanks Gareth. Unfortunately then something is going wrong here. > I created the link_to_remote - > <%= link_to_remote "Search for jobs", {:controller => ''ajaxsearch'', > :action => ''search''}, {:href => > url_for(:controller => ''searches'', :action => ''new'')}%> > > I believe that is right. With javascript turned on the link does nothing. > > With js off, I get taken to the right place. > > Page source : > <a href="/searches/new" onclick="new Ajax.Request('''', {asynchronous:true, > evalScripts:true}); return false;">Search for jobs</a> > > Am I totally lame and missing something or is something weird going on ? > > Stuart >Alright, I think I got it now , I added the needed div / dom id. Which updated the page the link is on. I guess that is the way it''s intended to work. Stuart -- http://en.wikipedia.org/wiki/Dark_ambient --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Dark Ambient <sambient@...> writes:> Alright, I think I got it now , I added the needed div / dom id. Which updated > the page the link is on. I guess that is the way it''s intended to work. > > StuartThat''ll be my bad, for trying to guess the link_to_remote function call. Well done for working it out --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---