Ruby on Rails
HowtoWorkWithSessions

Sessions in 30 seconds1

Setting a session value2:

session[:greeting] = "Hello world!"

Reading a session value:

session[:greeting] # => "Hello world!"

Deleting a single session value:

session[:greeting] = nil

Completely removing a previously-set key/value pair3:

[not possible]

Clearing an entire session:

reset_session

Gotchas with sessions

A more in depth explanation available at HowtoAvoidSessionRestoreError

3 Key/Value pair removing workaround

There can be a possible workaround IF

  1. lot of session variables going to be used and we worry about the amount of resources going to be allocated
  2. we like our session information to be easy to read, manage and debug
  3. we need more control over session variables we created

More information

See also

Questions/Noob remarks

gave


You have a nil object when you didn't expect it !
...
occured while evaluating nil.[]=

Um. What are you even doing using the constructor anyway? Surely before_filter is the way.


1 section shamelessly lifted from >DHH email

2 “session[:foo]” (a method call) is preferred to “@session[:foo]” (an instance variable) although you will often see the latter.