Achieving Multitenancy in a Rails App Using CurrentAttributes | Hashrocket

08-Aug-2025 49
While working with a legacy BBj PRO/5 database for a client, we needed to set up a new CMS with multitenancy requirements. We were dealing with a slew of foreign tables representing the PRO/5 data, and each of the tables had a column for designating which tenant they belonged to. Let's talk about how we leveraged ActiveSupport::CurrentAttributes to solve this problem! Our Requirements Our client was dealing with an organization that had multiple children "companies" with different rules, ecommerce settings, and locales. While the companies were being treated as separate entities, our CMS users were meant to be able to easily jump between the companies while doing their work. This meant that we didn't need an extremely strong level of security between the companies, as they were all under the same umbrella, and our users were free to see the data across all of the companies. It also meant that our users needed to be able to jump between tenants easily.
Use coupon code:

RUBYONRAILS

to get 30% discount on our bundle!
Prepare for your next tech interview with our comprehensive collection of programming interview guides. Covering JavaScript, Ruby on Rails, React, and Python, these highly-rated books offer thousands of essential questions and answers to boost your interview success. Buy our 'Ultimate Job Interview Preparation eBook Bundle' featuring 2200+ questions across multiple languages. Ultimate Job Interview Preparation eBook Bundle