top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

What is the difference between render and redirect in Ruby on Rails?

+1 vote
451 views
What is the difference between render and redirect in Ruby on Rails?
posted Oct 27, 2014 by Amit Kumar Pandey

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes
  1. Redirect is a method that is used to issue the error message in case the page is not found or it issues a 302 to the browser. Whereas, render is a method used to create the content.

  2. Redirect is used to tell the browser to issue a new request. Whereas, render only works in case the controller is being set up properly with the variables that needs to be rendered.

  3. Redirect is used when the user needs to redirect its response to some other page or URL. Whereas, render method renders a page and generate a code of 200.

  4. Redirect is used as:

    redirect_to: controller => ‘users’, :action => ‘new’

Render is used as:

render: partial
render: new -> this will call the template named as new.rhtml without the need of redirecting it to the new action.
answer Oct 28, 2014 by Kali Mishra
...