1

I have two applications running on different rails versions; rails 2.3.18 and rails 4.2.1. I need to share the session between them so that logging into one application would also login into the other. I have the following configuration:

Rails 2.3

# config/initializers/session_store.rb
ActionController::Base.session = {
  key: '_custom_session',
  secret: 'xyz' }

# config/initializers/cookie_verification_secret.rb
ActionController::Base.cookie_verifier_secret = 'xyz'

Rails 4.2

# config/initializers/session_store.rb
Rails.application.config.session_store :cookie_store, key: '_custom_session'
Rails.application.config.action_dispatch.cookies_serializer = :marshal
Rails.application.config.secret_token = 'xyz'

# config/secrets.yml
# Removed the *secret_key_base*.

On logging into the Rails 4 app, a new cookie named _custom_session was created. The rails 2 app was also able to access the same cookie. This implied that the cookie was shared. However the user was not logged into the rails 2 app. Accessing the rails 2 app rewrote the shared cookie thus logging out the rails 4 user.

I also tried setting the domain manually, but that didn't help either:

Rails.application.config.session_store :cookie_store, key: '_custom_session', domain: '.rails.local'

Any help would be appreciated.

Alex
  • 1,618
  • 1
  • 17
  • 25
  • If they are running in the same domain have a look at [This Post](http://stackoverflow.com/questions/10402777/share-session-cookies-between-subdomains-in-rails/10403338#10403338). Or have a look at [This Article](http://kabisa.nl/share-sessions-between-rails-2-and-rails-3-applications/) as it walks you through step by step for Rails 2 to Rails 3 so I would assume you could make it work for 4. – engineersmnky Jun 01 '15 at 13:30
  • Thanks, but none of those solutions worked. – Alex Jun 02 '15 at 07:46
  • I was able to share the sessions between my 2 apps (Same as @Alex, Rails 2.3 and Rails 4.2) but through Redis (using the redis-sessions-store gem). Unfortunately, while it is working fine regarding the login, the flash messages aren't working (for now). – ZedTuX Nov 23 '16 at 07:14

1 Answers1

1

Have you tried moving the session from the cookie store to storing it in the DB using activerecord-session_store?

From:

Rails.application.config.session_store :cookie_store, key: "_rails_session_#{Rails.env}", domain: :all

To something like:

Rails.application.config.session_store :active_record_store, :key => 'your_session_key_name'