Learn
Authentication
Logout

Nice job! Now when you fill in the login form and submit it, the data is sent to the Rails app via a POST request. The request hits the Sessions controller’s create action. The create action checks whether your email and password exist in the database, creates a new session, and redirects to the albums page.

Instructions

1.

Now that users can log in, let’s add the ability to log out.

In the routes file, create a route that maps the URL /logout to the Sessions controller’s destroy action:

delete 'logout' => 'sessions#destroy'
2.

In the Session controller, add the destroy action by setting the session hash to nil and redirecting to the root path

def destroy session[:user_id] = nil redirect_to '/' end
Folder Icon

Sign up to start coding

Already have an account?