rails-tenantify is a Ruby gem (v0.1.2) that adds row-level multi-tenancy to Rails 7+ apps using a single database. It scopes ActiveRecord models to a tenant via a foreign key, automatically sets the FK on record creation, and guards bulk operations like update_all/delete_all against cross-tenant writes. Tenant context is resolved from subdomains or HTTP headers in controllers, serialized into ActiveJob and Sidekiq job payloads for background job safety, and validated on cross-tenant associations. It includes RSpec test helpers, audit logging for unsafe tenant overrides, and a configuration API. Compared to acts_as_tenant, it offers better Rails 7 support, built-in Sidekiq retry safety, and guarded bulk writes.

9m read timeFrom github.com
Post cover image
Table of contents
Table of contentsCompatibilityWhy rails-tenantify?InstallationSetup guide (step by step)Configuration referenceModelsControllers & resolversSetting tenant from the current userTenant context APIBackground jobsBulk-write protectionCross-tenant associationsTestingAPI referenceWhat ships in 0.1.2RoadmapDevelopmentContributingLicense
251 Impressions