# Redirect\_to or render

**URL:** <https://www.ruby-forum.com/t/redirect-to-or-render/130517>\
**Category:** Rails\
**Created:** [February 28, 2008, 11:21pm UTC](https://www.ruby-forum.com/t/redirect-to-or-render/130517 "2008-02-28T23:21:58Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![shaish](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/bcef8e/32.png) [@shaish](https://www.ruby-forum.com/u/shaish)\
**Post date:** [February 28, 2008, 11:21pm UTC](https://www.ruby-forum.com/t/redirect-to-or-render/130517/1 "2008-02-28T23:21:58Z")

</div>

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 !

---

<div class="post-metadata">

**Author:** ![shaish](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/bcef8e/32.png) [@shaish](https://www.ruby-forum.com/u/shaish)\
**Post date:** [February 28, 2008, 11:26pm UTC](https://www.ruby-forum.com/t/redirect-to-or-render/130517/2 "2008-02-28T23:26:05Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![shaish](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/bcef8e/32.png) [@shaish](https://www.ruby-forum.com/u/shaish)\
**Post date:** [February 28, 2008, 11:27pm UTC](https://www.ruby-forum.com/t/redirect-to-or-render/130517/3 "2008-02-28T23:27:15Z")

</div>

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)
