Requirements to advance
- The user should be able to create an account and log in.
- The user should see a prompt to log in if they aren't logged in.
- Once logged in, the user should see a static page with some kind of greeting.
- The page should display the logged-in user's email address and a link to log out.
The purpose of this section is to allow users to log in to your app and demonstrate how to add external libraries like Devise using the Gemfile. If you find yourself needing to write more than a couple of lines of code to make that happen, you may have gone too far. Talk to a TA!
- What is Devise?
- What files did Devise add to your rails app?
- Someone Who Knows: explain how to read the output of the command
rails routes. What does it give you? How is it helpful?
- How will you add the log out link? What's the syntax for a DELETE action?
- You're going to be editing your application layout to add error messaging. If you haven't already, discuss the relationship between the application layout and all the other views you'll be creating.
Tools and References
- Devise: authentication magic! Learn more about it here: https://github.com/plataformatec/devise
- In the readme, scroll down to "Getting Started." You'll need to add it to your gem file. If you don't remember how, ask your neighbor!
- You probably don't want to just start typing commands from the Devise readme. You probably want to read through that whole section first. (i.e., don't skip bundle!)
- Readme files are your best friends! Love them!
- The convention for naming models is to capitalize the first letter, like: User.
- When you run
rails generate devise:install, you get five instructions for things to configure. 3 & 4 are good to do.
- The routes file goes through many common types of routes in the comments. This is also your friend.
- Devise has some magic that will help you with your logout link. Run
rails routesand look for a route that helps you sign out.
- You'll probably want to show the current user's email address only if they are presently signed in, right? Devise has a helper for you.
- Optional: any time you generate a model in rails, you can use Rails Console to look at that model's methods and behavior interactively.