Rails stores the user's ID in the session to identify the user on subsequent requests. Storing passwords or entire user objects is insecure or inefficient.
Calling session.clear removes all session data, ensuring the user is fully logged out. Deleting only :user_id or setting it to nil may leave other session data intact.
In Rails, session behaves like a hash. You assign values using square brackets and =. Options B, C, and D are invalid syntax or comparison instead of assignment.
session[:user_id] = @user.id redirect_to dashboard_path
If the session store is not set up, Rails cannot save session data between requests, causing session[:user_id] to be nil after redirect.
Rails sessions by default use cookie store, which stores data on the client side. Even though cookies are signed and encrypted, storing sensitive data like passwords is risky and unnecessary.