Recall & Review
beginner
What is the purpose of the
session in a Rails login flow?The
session stores user information temporarily to keep the user logged in across different pages until they log out or the session expires.Click to reveal answer
beginner
Which Rails controller action typically handles user login?
The
create action in the SessionsController usually handles user login by verifying credentials and setting the session.Click to reveal answer
beginner
How does Rails usually handle user logout?
Rails handles logout by clearing the user session, often in the
destroy action of the SessionsController, which removes the user ID from the session.Click to reveal answer
intermediate
Why is it important to use
has_secure_password in the User model?It securely hashes passwords and provides authentication methods, making login safer by not storing plain passwords.
Click to reveal answer
intermediate
What is a common way to restrict access to certain pages for logged-in users only?
Use a
before_action filter in controllers to check if a user is logged in by verifying the session, redirecting if not.Click to reveal answer
In Rails, where is the user ID usually stored after a successful login?
✗ Incorrect
Rails stores the user ID in the session hash to keep track of the logged-in user securely during their visit.
Which controller action is responsible for logging out a user in a typical Rails app?
✗ Incorrect
The destroy action clears the session to log the user out.
What does
has_secure_password add to a Rails User model?✗ Incorrect
It adds secure password hashing and authentication helpers.
How can you protect a controller action so only logged-in users can access it?
✗ Incorrect
A before_action filter checks if the user is logged in before allowing access.
What happens if a user tries to access a protected page without logging in?
✗ Incorrect
The app redirects unauthorized users to the login page to protect content.
Explain the steps of a typical login flow in a Rails application.
Think about what happens from form submission to session storage.
You got /4 concepts.
Describe how logout works in Rails and why it is important.
Focus on session clearing and user redirection.
You got /4 concepts.