Rails has a session management mechanism already built for you. Just
use that. Store your value in the session hash then you can just
configure Rails to store sessions either in a file (the default) or in
the database if you prefer that.
Excerpt from Agile Web D. with Rails page 105:
By default, Rails stores session information in a file on the server.
If you have
a single Rails server running, there’s no problem with this. But
your store application gets so wildly popular that you run out of
capacity on a
single-server machine and need to run multiple boxes. The first
a particular user might be routed to one back-end machine, but the
request might go to another. The session data stored on the first
available on the second; the user will get very confused as items
disappear in their cart across requests.
If you choose to store session data in the database just do this:
depot> rake db:sessions:create
depot> rake db:migrate
And here’s a sample of storing an object in the session:
unless session[:cart] # if there’s no cart in the
session[:cart] = Cart.new # add a new one
session[:cart] # return existing or new cart