0
0
Ruby on Railsframework~5 mins

Login and logout flow in Ruby on Rails - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
AIn the session hash
BIn a cookie without encryption
CIn the database permanently
DIn the params hash
Which controller action is responsible for logging out a user in a typical Rails app?
Anew
Bcreate
Cedit
Ddestroy
What does has_secure_password add to a Rails User model?
AEmail validation
BPassword hashing and authentication methods
CSession management
DUser role management
How can you protect a controller action so only logged-in users can access it?
AUse <code>after_action</code> to redirect
BAdd a <code>skip_before_action</code>
CUse <code>before_action</code> to check session user ID
DStore user info in params
What happens if a user tries to access a protected page without logging in?
AThey are redirected to the login page
BThey see the page anyway
CThe app crashes
DThey get logged in automatically
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.