Hi. I have a basic question here. How exactly does a redirect_to (HTTP 302) work? If I have a redirect_to(URL), does it basically send back an HTTP 302 back to the client, as in browser and then the browser asks for the redirect_to URL? Or, do the redirection happen on the web server without going back to the client? I''m a little confused here because I would imagine that a redirect_to would slow things down. Say I have a login controller and a user controller. If a user signs in, I have them execute the login/login controller/action and if that is successful, I will redirect_to them to an action in the user/index controller/action. If the redirect_to causes another roundtrip, wouldn''t it be better to just execute the user action and template in the login controller? Thanks for your help. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On 11/23/06, Sam <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > > Hi. I have a basic question here. How exactly does a redirect_to (HTTP > 302) work? If I have a redirect_to(URL), does it basically send back an > HTTP 302 back to the client, as in browser and then the browser asks for > the redirect_to URL? Or, do the redirection happen on the web server > without going back to the client? I''m a little confused here because I > would imagine that a redirect_to would slow things down. > > Say I have a login controller and a user controller. If a user signs > in, I have them execute the login/login controller/action and if that is > successful, I will redirect_to them to an action in the user/index > controller/action. If the redirect_to causes another roundtrip, > wouldn''t it be better to just execute the user action and template in > the login controller? > > Thanks for your help. > > >redirect_to does indeed send a 302 response to the browser, which causes the browser to make a new request at the redirect URL. A whole new web request occurs, and none of the code executed before the redirect is retained in memory. -- Scott Becker Electro Interactive, Inc. Office: 813-333-5508 http://www.ElectroInteractive.com --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
The redirect sends back as part of the response a Location header that tells the browser where to go. You could just call the appropriate methods, render the right template and so on, but that''s not really a good idea: The browser still thinks its addressing the original resource, so reload, back and so on won''t do the right thing: Common example: On a blog you submit a comment, and are redirected to a page showing the comments. If you hit refresh, you just see the comment list again. If you had just done a render, then the browser thinks it''s still on the comment submission page => refreshing would submit again. Fred -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---