From the course: Ruby on Rails 6 Essential Training

Unlock the full course today

Join today to access over 22,500 courses taught by industry experts or purchase this course individually.

Redirect controller actions

Redirect controller actions - Ruby on Rails Tutorial

From the course: Ruby on Rails 6 Essential Training

Start my 1-month free trial

Redirect controller actions

- [Instructor] In this movie, we'll learn how to redirect actions from the controller. Controllers can respond to requests by rendering a view. But that's not their only choice. They can also redirect or send the user to a different controller and action. Imagine this scenario, a user requests a web page that's inside a password protected area. The code will check to see if the users logged in or not before giving them back that template. If they are logged in, then they'll be able to see the page. But if they're not logged in, then we want to redirect them to a login page so that they can enter their username and password. We could choose to just render the login template but that's not quite what we want. We want the URL in the browser to change to the new page. And we want the opportunity to execute more code that's associated with the login page. The two may seem similar but it's an important difference in practice.…

Contents