We generally use cookie based session storage technique.Storing sessions in the database in however very important.
Rails provide an built-in feature using rake to create session table .
- Create Migration
$ rake db:sessions:create
The above command will create the migration required for session table.
now , using
2. Create table
$ rake db:migrate
Session table has been created.
After Table creation , we need to tell rails that use this table for session storage.
Open this file config/initializers/session_store.rb in any editor.
Edit Config file
Comment ActionController::Base.session section
and uncomment this line is to tell you want to use database for session storage.
4. Restart server
Restart your server after modifying and saving the above file.
I will tell more about how to use sessions in my next post.