Skip to content
Tags

Difference between render and redirect_to

August 3, 2011

This discussion explains that well:

http://groups.google.com/group/rubyonrails-talk/browse_thread/thread/d8186a2d640a1b7f

 

Here is a part of that discussion –

> 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)


Advertisements

From → Uncategorized

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: