Rails for web applications enables sharing sessions between different applications built on Rails 4. It allows the data of one application to be used in the other application. Sometimes, data sharing between multiple applications becomes difficult when both are of the same domain. In such an instance, a Ruby on Rails developer will share the session to ensure that data can be used from a single session within both the applications. 

An RoR application built by a Ruby on Rails development company needs to fulfil a certain set of requirements before data can be shared with a session. Let’s look at how it is done.

Scenario

I have a Rails application which loads a few pages from another application in iframe (yeah! I know it is bad) sharing the same domain. The main Rails applications save some data in session which is used by the other application. Also, when a user is interacting within an iframe UI, the session should not get timed out in the container Ruby on Rails application.

Assumptions

  1. Both applications shares same domain
  2. Both applications run on Ruby on Rails 4.2.x
  3. One application handles authentication via Devise and shares session with other application
  4. Session will be stored on memcached via AWS elasticache service
  5. dalli and dalli-elasticache gems are configured in Gemfile.
    dalli-elasticache is a gem for AWS ElastiCache Auto Discovery support for Memcached

Implementation

Make following changes in both applications:

  • Set the same session cookie name and domain scope in session_store.rb

config/initializers/session_store.rb
  • Set same secret base in secrets.yml

config/secrets.yml
  • Use shared memcached client to share sessions

config/application.rb

And that’s it. You can now call other application pages in one application and share data through session. The simple process enables you to work in a single session for two separate Rails applications and share the data within them.