How to Share Session between Rails Applications?
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.
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.
- Both applications shares same domain
- Both applications run on Ruby on Rails 4.2.x
- One application handles authentication via Devise and shares session with other application
- Session will be stored on memcached via AWS elasticache service
dalli-elasticachegems are configured in Gemfile.
dalli-elasticacheis a gem for AWS ElastiCache Auto Discovery support for Memcached
Make following changes in both applications:
- Set the same session cookie name and domain scope in
- Set same secret base in
- Use shared memcached client to share sessions
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.
Sample snippet showing how one application access pages of other application.
Consulting is free - let us help you grow!
Choose Your Language
- Digital Marketing
- IT Consulting
- Project Management