Recall & Review
beginner
What is a session in Rails?
A session in Rails is a way to store data about a user across multiple requests. It helps keep track of user information like login status while they browse the site.
Click to reveal answer
beginner
How does Rails store session data by default?
By default, Rails stores session data in a cookie on the user's browser. This cookie is encrypted and signed to keep data safe and prevent tampering.
Click to reveal answer
beginner
How do you set a value in the session in a Rails controller?
You set a session value by assigning it like a hash: <br>
session[:user_id] = 123 This saves the user ID in the session for later use.Click to reveal answer
intermediate
What is the difference between session and cookies in Rails?
Cookies store data directly on the browser and can be read by client-side scripts. Sessions store data encrypted and signed in cookies and are used to keep user state securely across requests.
Click to reveal answer
beginner
How can you clear all session data in Rails?
You can clear all session data by calling
reset_session in a controller. This removes all stored session information for the user.Click to reveal answer
Where is session data stored by default in Rails?
✗ Incorrect
Rails stores session data in an encrypted cookie on the user's browser by default.
How do you access session data in a Rails controller?
✗ Incorrect
Session data is accessed via the session hash, for example session[:user_id].
What method clears all session data in Rails?
✗ Incorrect
The reset_session method clears all session data for the current user.
Which of these is true about Rails sessions?
✗ Incorrect
Rails encrypts and signs session data stored in cookies to keep it secure.
What is a common use of sessions in Rails apps?
✗ Incorrect
Sessions commonly store temporary data like user login status during browsing.
Explain how Rails sessions help keep track of a user across multiple pages.
Think about how a website remembers you after you log in.
You got /4 concepts.
Describe how to set, access, and clear session data in a Rails controller.
Focus on the session hash and controller methods.
You got /3 concepts.