Do the following if you want to have sessions that are stored in the database.
config/environment.rb
config.action_controller.session_store = :active_record_store
rake db:sessions:create. This will create a migrations file, ###_add_sessions.rb
rake db:migrate.
Rails 2.0 has better support for cookie-based sessions and supports it out of the box.
To help configure sessions, do the following.
/config/environment.rb
require 'yaml'
session = YAML.load_file('config/session.yml')
config.action_controller.session = {
:session_key => session[RAILS_ENV]['session_key'],
:secret => session[RAILS_ENV]['secret']
}
session.yml in the directory /config and edit it with your own values.# This is an example settings file for Rails 2.0 cookie-based sessions. # To generate a secret phrase, use 'rake secret' development: session_key: _session_key secret: # a hashed string that is longer than 32 characters test: session_key: _session_key secret: # a hashed string that is longer than 32 characters production: session_key: _session_key secret: # a hashed string that is longer than 32 characters
rake secret on the command line.