Skip to content

Instantly share code, notes, and snippets.

@caward12
Forked from case-eee/sessions.md
Last active April 3, 2017 17:43
Show Gist options
  • Save caward12/eda9d670e10537907cb78ebb39b00c4c to your computer and use it in GitHub Desktop.
Save caward12/eda9d670e10537907cb78ebb39b00c4c to your computer and use it in GitHub Desktop.
Sessions, Cookies, and Flashes

Sessions, Cookies, and Flashes

  1. If we didn't have cookies and sessions, what would happen?
  • you would not be able to "hold on to" data between http requests since http is stateless - it does not know about any other requests previously made.
  1. What is a cookie?
  • a cookie is a key value pair stored in a user's browser until its specified experation date.
  1. What's the difference between a cookie and a session?
  • A session is an entire hash and is a secure version of a cookie. Cookies are just key value pairs. Session is stored server side and cookie is stored browser side.
  1. What's serialization and how does it come into play with sessions?
  • the value data is unreadable by humans and you have to have the key to "de-serialize" it. It makes session data more secure unlike cookie data that you can change easily.
  1. Why would we want to store a user id in a session?
  • to keep track of whether they are loggedin in or not, and their movement while logged in
  1. What is a flash? How long does a flash have before it expires?
  • a flash is a hash-like object that only persists from one request to another - mostly used to provide feedback to the user when submitting forms.
  1. What syntax would I use to add a user_id key and value to the session?
  • session[:user_id] = user.id
  1. What does "HTTP is stateless" mean?
  • it does not remember previous requests.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment