RubyFlow The Ruby and Rails community linklog

×

The Ruby and Rails community linklog

Made a library? Written a blog post? Found a useful tutorial? Share it with the Ruby community here or just enjoy what everyone else has found!

rails-tenantify — row-level multi-tenancy for Rails 7+

rails-tenantify adds row-level multi-tenancy to Rails 7+ apps — one database, one organization_id column, no external service. Every multi-tenant SaaS needs scoped queries, safe background jobs, and protection against cross-tenant bulk SQL. acts_as_tenant is showing its age on Rails 7. Apartment pushes schema-per-tenant ops. rails-tenantify is a small gem that does the boring parts right. What you get (v0.1.2): → belongs_to_tenant :organization on any model → set_tenant_by :subdomain (acme.yourapp.com → tenant) → set_tenant_by :header (X-Tenant-ID for APIs) → Tenantify.switch_to / without_tenant → ActiveJob + Sidekiq: tenant context on enqueue and retry → Guards update_all, delete_all, destroy_all → Cross-tenant belongs_to validation → RSpec helpers: with_tenant / without_tenant → audit_overrides: :log, :raise, or :ignore Quick start: gem “rails-tenantify”, “~> 0.1.2”, require: “rails-tenantify” Tenantify.configure { |c| c.tenant_model = “Organization” } class Project < ApplicationRecord include Tenantify::Scoped belongs_to_tenant :organization end class ApplicationController < ActionController::Base set_tenant_by :subdomain end Built from a real multi-school Rails app (online exam system) with automated tenant isolation checks. Subdomain tenants work today; full custom domains on the roadmap. RubyGems: https://rubygems.org/gems/rails-tenantify GitHub: https://github.com/sghani001/rails-tenantify MIT · PRs welcome

Post a comment

You can use basic HTML markup (e.g. <a>) or Markdown.

As you are not logged in, you will be
directed via GitHub to signup or sign in