0
0
Ruby on Railsframework~5 mins

Session handling in Ruby on Rails - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
AIn an encrypted cookie on the browser
BIn the database automatically
CIn a server-side file
DIn localStorage
How do you access session data in a Rails controller?
AUsing request[:key]
BUsing params[:key]
CUsing cookies[:key]
DUsing the session hash, like session[:key]
What method clears all session data in Rails?
Adelete_session
Bclear_session
Creset_session
Dremove_session
Which of these is true about Rails sessions?
ASession data can be encrypted and signed in cookies
BSession data is visible to client-side JavaScript by default
CSession data is always stored on the server
DSessions cannot store user login information
What is a common use of sessions in Rails apps?
ATo permanently save user data in the database
BTo store temporary user login status
CTo style the webpage dynamically
DTo send emails to users
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.