multi-tenancy

Implement secure multi-tenant Rails 8 apps with acts_as_tenant.

21|2|Updated May 24, 2026
One-click install
npx skills add https://github.com/sandeepmvl/rails-skills --skill multi-tenancy-sandeepmvl
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: multi-tenancy
Source: https://github.com/sandeepmvl/rails-skills/tree/main/skills/38-multi-tenancy
Command: npx skills add https://github.com/sandeepmvl/rails-skills --skill multi-tenancy-sandeepmvl

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

AI coding agents frequently generate flawed multi-tenant Rails implementations that expose critical security risks, including cross-tenant data leaks, use of deprecated or fragile patterns like the unmaintained apartment gem, and broken background job tenancy that fails to isolate customer data.

Core Features & Use Cases

  • Pattern trade-off guidance: Clear recommendations for row-scoped, schema-per-tenant, and database-per-tenant multi-tenancy, with explicit guidance on when to use each pattern for different compliance and operational needs.
  • Production-ready implementation steps: Step-by-step instructions for setting up acts_as_tenant, resolving tenants via subdomain, path, or API header, scoping background jobs, isolating sessions and file storage, and implementing plan-based feature gating.
  • Critical bug prevention: Explicit guardrails and test patterns to avoid the most common multi-tenant mistakes, including unscoped queries, missing tenant_id indexes, and cross-tenant data access. Use case: For B2B SaaS Rails applications where each customer account requires isolated data, this skill ensures AI agents implement compliant, secure multi-tenancy that aligns with senior Rails developer best practices.

Quick Start

Use the multi-tenancy skill to implement row-scoped tenant isolation with acts_as_tenant for your Rails SaaS app, including subdomain-based tenant resolution and background job tenancy.

Frequently Asked Questions about multi-tenancy

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I prevent cross-tenant data leaks in a Rails SaaS application?

Prevent cross-tenant data leaks in a Rails SaaS application by enforcing automatic query scoping using acts_as_tenant, which ensures all database queries are strictly filtered by tenant_id and eliminates unscoped data access.

What is the best way to isolate background jobs in a multi-tenant Rails app?

Isolate background jobs in a multi-tenant Rails app by passing the tenant context to job workers and re-scoping queries within the job execution. This prevents broken job tenancy and ensures customer data remains isolated during asynchronous processing.

When should I choose row-scoped vs schema-per-tenant multi-tenancy in Rails?

Choose row-scoped multi-tenancy for simpler operational needs and schema-per-tenant when strict compliance requires isolated database schemas. Row-scoping uses tenant_id columns with acts_as_tenant, while schema-per-tenant separates customer data at the database schema level.

Does acts_as_tenant work with Rails 8 for B2B SaaS tenant isolation?

Yes, acts_as_tenant works with Rails 8 to provide production-grade tenant isolation for B2B SaaS applications. It replaces deprecated patterns like the apartment gem and supports subdomain, path, or API header tenant resolution.

How do I resolve tenants via subdomain or API header in a multi-tenant Rails app?

Resolve tenants via subdomain or API header in a multi-tenant Rails app by setting up a tenant resolution mechanism that identifies the customer account from the request context, then automatically scoping all subsequent database queries to that specific tenant.

Why are unscoped queries dangerous in multi-tenant Rails applications?

Unscoped queries are dangerous in multi-tenant Rails applications because they bypass tenant isolation filters, allowing users to access or modify data belonging to other customer accounts. This creates critical cross-tenant data leak vulnerabilities and compliance violations.