1
votes

I have 2 rails applications (version 4.0 and 4.1) which have their own database and a secound db-connector to the other database. Both apps have a login-form and now I want to share the session.

In both apps I added the activerecord-session_store gem and in the config/initializers/seesion_store.rb file I set session_store to active_record_store.

How can I tell one app that it use the other database (not the default db-connector) to store the session?

Is there a way to share sessions with cookies? Both apps have different URLs.

I'm looking forward to your reply.

1
Your comment / answer was really helpful. Took a lot of googling to find. Would be better if you resubmitted as an answer to your own question IMO. Anyway thanks for the help :) - newUserNameHere

1 Answers

1
votes

You may override the session store class with your own class and have the functionality to write and read sessions from your second database.

Example class:

https://github.com/rails/activerecord-session_store/blob/master/lib/active_record/session_store/sql_bypass.rb

Here, you can have connection return your second db connection.

Referring to doc:

https://github.com/rails/activerecord-session_store

You may provide your own session class implementation, whether a feature-packed Active Record or a bare-metal high-performance SQL store, by setting

ActionDispatch::Session::ActiveRecordStore.session_class = MySessionClass

You must implement these methods:

self.find_by_session_id(session_id)
initialize(hash_of_session_id_and_data, options_hash = {})
attr_reader :session_id
attr_accessor :data
save
destroy

The example SqlBypass class is a generic SQL session store. You may use it as a basis for high-performance database-specific stores.