Adding Log Out
To log out of the application, we can add a button to the top of . This layout is where you put HTML that you want to include in every page like a header or footer.
Add a small <nav>
section inside the <body>
with a link to Home and a Log
out button and wrap yield
with a <main>
tag.
<!DOCTYPE html><html> <!-- ... --> <body> <nav> <%= link_to "Home", root_path %> <%= button_to "Log out", session_path, method: :delete if authenticated? %> </nav>
<main> <%= yield %> </main> </body></html>
This will display a Log out button only if the user is authenticated. When clicked, it will send a DELETE request to the session path which will log the user out.
Files
Preparing Environment
- Preparing Ruby runtime
- Prepare development database