Hey, a newbie here. Can someone please give me a brief explanation whats the difference between the redirect_to method and the render method and when should I use one instead of the other ? thnx alot ! --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
redirect_to will issue a 302 to the browser, so that the browser will issue a new request. render will create content. You have to make sure that your controller has set up all of your variables for any render that you create. If you are going to cross controllers, or you do not have enough information to call a particular render, then you want to use redirect_to. If you choose between rss/html or one layout vs. another, then you can use render. On Feb 28, 4:21 pm, shaish <shai.sh...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hey, a newbie here. > Can someone please give me a brief explanation whats the difference > between the redirect_to method and the render method and when should I > use one instead of the other ? > thnx alot !--~--~---------~--~----~------------~-------~--~----~ 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 Feb 28, 2008, at 2:21 PM, shaish wrote:> Hey, a newbie here. > Can someone please give me a brief explanation whats the difference > between the redirect_to method and the render method and when should I > use one instead of the other ? > thnx alot !Use redirect_to when you want the browser to receive a 302 redirect response and go to another URL. Use render when you don''t need the browser to issue another request, but can render a page and return a 200. Examples: - User fills in form in new action - Fields are filled in incompletely or incorrectly - Post goes to the create action, which understands that and renders the ''new'' template again with a 200 so the user can fix errors - User fills in form in new action - Fields are filled in correctly - Post goes to create and information is successfully added to the database - You issue a redirect to the index page (or something) --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---