What is the difference between render and redirect_to in Rails?

Answer

render generates an HTTP response by rendering a view template and returning it to the browser in the same request. The URL in the browser does not change. Example: render :new when create fails (re-displays the form with errors). redirect_to sends a 302 HTTP redirect response, causing the browser to make a new GET request to the specified URL. The URL changes. Example: redirect_to @post after successful create. The Post/Redirect/Get (PRG) pattern prevents duplicate form submissions on browser refresh.