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 .

  1. 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.

3.  Configure

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.

<applicationname>::Application.config.session_store :active_record_store

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.





Storing Sessions in the Database

Leave a Reply

Your email address will not be published.