Andrew Edwards
2008-Sep-18 13:05 UTC
respond_to js and redirect - inconsistent results forwarding JS requirement
Hi, I have the following simple piece of code in one of my actions: respond_to do |format| format.js { redirect_to basket_url } end In Safari this works fine and the basket controller''s show action is called and returns a rjs response. However in Firefox it calls the show action on basket but instead returns an html response, it doesn''t seem to detect the call came from a forwarded js request. The only way I have found around this to get consistent results is: respond_to do |format| format.js { redirect_to formatted_basket_url(:format => :js) } end Is this correct? On a related note I''ve also had instances where the order of the format.js, format.html etc in the respond_to block has influenced what has been rendered (mainly browsing with IE)?? Is there a reason or pattern to this? Thanks, Andrew --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Andrew Edwards
2008-Sep-18 14:25 UTC
Re: respond_to js and redirect - inconsistent results forwarding JS requirement
I think I might have found a reason, just in case anyone has a similar issue. I may have misunderstood what was happening on a redirect_to call in the action. I assumed it was an internal redirection within the server between the two actions and it didn''t inform the browser, just rendered the end result. In reality it is sending a normal 302 redirect response to the browser and this is then submitting a new request. It appears on Safari the redirected GET request is inheriting the js accept info from the original request, however on Firefox it doesn''t make this link. Hence the reason the formatted_basket_url is needed to force the issue and ensure there is no doubt over which response we need. At least that''s my take on it, if anyone knows different let me know. On 18 Sep, 14:05, Andrew Edwards <and...-ZYDPpGlny4uS7RsuTa25KztV0T984lsv@public.gmane.org> wrote:> Hi, > > I have the following simple piece of code in one of my actions: > > respond_to do |format| > format.js { redirect_to basket_url } > end > > In Safari this works fine and the basket controller''s show action is > called and returns a rjs response. However in Firefox it calls the > show action on basket but instead returns an html response, it doesn''t > seem to detect the call came from a forwarded js request. > > The only way I have found around this to get consistent results is: > > respond_to do |format| > format.js { redirect_to formatted_basket_url(:format => :js) } > end > > Is this correct? > > On a related note I''ve also had instances where the order of the > format.js, format.html etc in the respond_to block has influenced what > has been rendered (mainly browsing with IE)?? Is there a reason or > pattern to this? > > Thanks, > > Andrew--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---