From the course: Ruby on Rails 5 Essential Training

Unlock the full course today

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

Login and logout

Login and logout - Ruby on Rails Tutorial

From the course: Ruby on Rails 5 Essential Training

Start my 1-month free trial

Login and logout

- [Instructor] In the last movie we created the routes, controller, and view templates we need for user authentication. In this movie we'll add the controller actions to handle logging in and logging out. So let's start with coding the attempt_login. So attempt_login is what happens when the login form is submitted and we should have two parameter values that we receive, one for username and one for password. Let's start by just checking to make sure that those are sent to us. If params[:username].present?, present is a rails method that is the opposite of blank. So it's exactly like blank, but it's the opposite. So it's not blank, so username is not blank, and params[:password] is present, or not blank, then we're going to try to find the user in the database. If we haven't gotten them then we're not even going bother trying to go the database. No reason to look it up. We know it will fail. So next we want to try and find the user in the database, and then we'll check to see if the…

Contents