0
0
Ruby on Railsframework~20 mins

Session-based authentication in Ruby on Rails - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Session Auth Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
What happens after a successful login in a Rails session-based authentication?
In a typical Rails app using session-based authentication, what is stored in the session after a user logs in successfully?
ANo data is stored; the session remains empty after login.
BThe user's password is stored in the session for quick verification.
CThe entire user object is serialized and stored in the session.
DThe user's ID is stored in the session hash to identify the logged-in user.
Attempts:
2 left
💡 Hint
Think about what minimal information is needed to recognize the user on future requests.
lifecycle
intermediate
2:00remaining
What happens when a user logs out in a Rails session-based authentication?
Which action correctly clears the session to log out a user in Rails?
Asession[:user_id] = nil but session data remains intact.
Bsession.clear to remove all session data.
Csession[:user_id] = false to mark user as logged out.
Dsession.delete(:user_id) to remove the user ID from the session.
Attempts:
2 left
💡 Hint
Think about removing all session data to ensure complete logout.
📝 Syntax
advanced
2:00remaining
Identify the correct way to set a session variable in Rails controller
Which of the following code snippets correctly sets the current user's ID in the session?
Asession.user_id = current_user.id
Bsession.set(:user_id, current_user.id)
Csession[:user_id] = current_user.id
Dsession['user_id'] == current_user.id
Attempts:
2 left
💡 Hint
Remember how to access and assign values in a Ruby hash.
🔧 Debug
advanced
2:00remaining
Why does the session not persist after redirect in Rails?
Consider this code snippet in a Rails controller: ```ruby session[:user_id] = @user.id redirect_to dashboard_path ``` But after redirect, session[:user_id] is nil. What is the most likely cause?
Ruby on Rails
session[:user_id] = @user.id
redirect_to dashboard_path
AThe session store is not configured properly, so session data is not saved.
BThe redirect_to method clears the session automatically.
CThe session hash is read-only and cannot be assigned.
D@user.id is nil, so nothing is stored in the session.
Attempts:
2 left
💡 Hint
Check if the app has a session store configured in config/initializers or environment files.
🧠 Conceptual
expert
3:00remaining
Why is storing sensitive data in Rails session discouraged?
Which is the best explanation for why sensitive data like passwords should not be stored in Rails sessions?
ASessions are stored client-side as cookies, which can be read or tampered with by users.
BRails sessions expire immediately, so sensitive data is lost too soon.
CSessions automatically encrypt all data, so storing sensitive data is safe.
DStoring sensitive data in sessions causes the server to crash.
Attempts:
2 left
💡 Hint
Think about where session data is stored and who can access it.