Rails shared sessions with activerecord

后端 未结 4 1831
时光取名叫无心
时光取名叫无心 2020-12-29 16:26

I\'m currently using the default cookies as my single sign on (SSO) but some users are getting strange errors after I push an update. I\'m considering moving to active recor

相关标签:
4条回答
  • 2020-12-29 16:46

    The rails docs for the session configuration(http://api.rubyonrails.org/classes/ActionController/SessionManagement/ClassMethods.html#M000312) says that these are the only options: http://api.rubyonrails.org/classes/ActionController/Base.html#M000523. Since an option for which database to use isn't listed, it probably doesn't exist.

    0 讨论(0)
  • 2020-12-29 17:04

    In rails 2.3

    open config/initializers/session_store.rb

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

    change the key's value on the line which looks like :key => '_YOUR_APP_NAME_session'

    then restart your server.

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

    0 讨论(0)
  • 2020-12-29 17:08

    Rails most certainly does support database session storage.

    In config/environment.rb, uncomment

    # config.action_controller.session_store = :active_record_store
    

    Examining \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)
    

    to use a connect 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 to the end of config/environment.rb

     CGI::Session::ActiveRecordStore::Session.establish_connection("sessions_#{RAILS_ENV}")
    
    0 讨论(0)
  • 2020-12-29 17:08

    Can we get some clarification on your question? Do you have multiple, different, Rails apps that you want to use the same session store? I ask because you mention SSO and multiple app servers.

    0 讨论(0)
提交回复
热议问题