]> git.openstreetmap.org Git - rails.git/blob - vendor/plugins/sql_session_store/README
Fix redirect on deleting a trace
[rails.git] / vendor / plugins / sql_session_store / README
1 == SqlSessionStore
2
3 This version of SqlSessionStore properly supports both CGI-based sessions (Rails < 2.3)
4 and Rack-based sessions released in Rails 2.3.  For the latest version of +SqlSessionStore+,
5 see:
6
7     http://github.com/nateware/sql_session_store/tree/master
8
9 To install, use:
10
11     script/plugin install git://github.com/nateware/sql_session_store.git
12
13 This version also includes the "native columns" feature, which enables +session[:xyz]+
14 to map directly to column +xyz+ in the sessions table transparently.  For info,
15 scroll down to "Step 4".
16
17 Note: Only Mysql, PostgreSQL, and Oracle are currently supported (others work,
18 but you won't see much performance improvement).
19
20 == Step 1
21
22 If you have generated your sessions table using rake db:sessions:create, go to Step 2
23
24 If you're using an old version of sql_session_store, run
25
26     script/generate sql_session_store [DB]
27
28 where DB is mysql, postgresql or oracle
29
30 Then run
31
32     rake db:migrate
33
34 to create the sessions table.
35
36 == Step 2
37
38 Add the code below in +config/environment.rb+, inside the initializers section
39
40   # Use SqlSessionStore instead of the standard ActiveRecord store
41   config.action_controller.session_store = :sql_session_store
42
43 Then, depending on your database type, add
44
45     SqlSessionStore.session_class = MysqlSession
46 or
47
48     SqlSessionStore.session_class = PostgresqlSession
49
50 or
51
52     SqlSessionStore.session_class = OracleSession
53
54 after the initializer section in environment.rb
55
56 == Step 3 (optional)
57
58 If you want to use a database separate from your default one to store
59 your sessions, specify a configuration in your database.yml file (say
60 sessions), and establish the connection on SqlSession in
61 environment.rb:
62
63    SqlSession.establish_connection :sessions
64
65 == Step 4 (optional)
66
67 If you want to store certain pieces of data as actual columns in the 
68 +sessions+ table transparently, simply update the sessions migration
69 to include the columns.  For example, if you wanted to store +user_id+
70 and +language+ as columns, your migration might look something like:
71
72     create_table :sessions do |t|
73       t.string  :session_id, :null => false, :references => nil, :unique => true
74       t.integer :user_id
75       t.string  :language
76       t.text    :data
77       t.timestamps
78     end
79
80 Then, use the "native columns" feature of the specific database driver:
81
82     OracleSession.native_columns = [:user_id, :language]
83
84 This will map these columns transparently for you. Simply access them like
85 normal columns:
86
87     session[:user_id]  = @user.id
88     session[:language] = @language
89
90 And the appropriate columns in the sessions table will be updated for you.
91
92 == IMPORTANT NOTES
93
94 1. The class name SQLSessionStore has changed to SqlSessionStore to
95    let Rails work its autoload magic.
96
97 2. You will need the binary drivers for Mysql or Postgresql.
98    These have been verified to work:
99
100    * ruby-postgres (0.7.1.2005.12.21) with postgreql 8.1
101    * ruby-mysql 2.7.1 with Mysql 4.1
102    * ruby-mysql 2.7.2 with Mysql 5.0