Rails shares sessions with activerecord

I currently use the default cookies as my single sign-on (SSO), but some users get weird errors after I click update. I am considering moving to an active record for storing sessions, but I was wondering how I would say that the sessions are in a different database?

So, if I store sessions through AR in App1DB, how can all other applications know where to look for sessions?

+6
ruby-on-rails activerecord session
source share
4 answers

Rails certainly support session database storage support.

In config / environment.rb, uncomment

# config.action_controller.session_store = :active_record_store 

Examination of \ actionpack-2.2.2 \ lib \ action_controller \ session \ active_record_store.rb shows that CGI :: Session :: ActiveRecordStore :: Session inherits from ActiveRecord :: Base.

So, at the end of config / environment.rb you should be able to say

 CGI::Session::ActiveRecordStore::Session.establish_connection( :adapter => "mysql", :host => "otherserver", :username => "session_user", :password => "123ABC", :database => "sessions") 

or

 CGI::Session::ActiveRecordStore::Session.establish_connection(:sessions) 

use the connection defined in config / database.yml


For example, add to config / database.yml:

  sessions_development: adapter: mysql host: otherserver username: sessions_user password: 123ABC database: sessions 

Add config / environment.rb to the end

  CGI::Session::ActiveRecordStore::Session.establish_connection("sessions_#{RAILS_ENV}") 
+9
source share

In rails 2.3

open configuration / initializers / session_store.rb

uncomment the line ActionController::Base.session_store = :active_record_store

change the key value on a line that looks like :key => '_YOUR_APP_NAME_session'

then restart the server.

The result will change your store and invalidate all old cookies.

+1
source share

Docs rails for session configuration ( http://api.rubyonrails.org/classes/ActionController/SessionManagement/ClassMethods.html#M000312 ) says these are the only options: http://api.rubyonrails.org/classes/ActionController/Base .html # M000523 . Since a parameter for which the database is not used is not specified, it probably does not exist.

0
source share

Can we get some clarification on your subject? Do you have several different Rails applications that you want to use in the same session store? I ask because you mention SSO and several application servers.

0
source share

All Articles