ݺߣ

ݺߣShare a Scribd company logo
Multi tenant/lang
application
Simon Courtois - @happynoff
Multi-tenant you say?
mywebsite.com

otherwebsite.com

and-another.com

APP
APP

middleware

switcher

Website
Website
domain
lang

class Website < ActiveRecord::Base
def self.current
Thread.current[:website]
end
!
def self.current=(website)
Thread.current[:website] = website
end
end

Website.current = Website.first
!
Website.current
# => #<Website domain=“mywebsite.com" lang="en">
APP

middleware

switcher

✔ Website
Website
switcher

class WebsiteSwitcher
attr_reader :domain, :host, :website

!

!

!

!

def initialize(host)
@host = host.downcase.chomp('.')
end
def domain
@domain ||=
ActionDispatch::Http::URL.extract_domain(host)
end
def website
@website ||= Website.where(domain: domain).first ||
Website.where(domain: 'mywebsite.com')
end

def switch!
Website.current = website
I18n.locale = website.lang
end
end
WebsiteSwitcher.new('www.mywebsite.com').switch!
APP

middleware

✔ switcher
switcher

✔ Website
middleware

require 'website_switcher'

!

class WebsiteSwitcherMiddleware
def initialize(app)
@app = app
end

!
!
!

def call(env)
request = Rack::Request.new(env)
WebsiteSwitcher.new(request.host).switch!

@app.call(env)
end
end
APP

✔ middleware
middleware

✔ switcher

✔ Website
require 'middlewares/website_switcher_middleware'

!
APP

module AwesomeApp
class Application < Rails::Application
# ...

!

config.middleware.use WebsiteSwitcherMiddleware
end
end
✔ APP
APP

✔ middleware

✔ switcher

✔ Website
Questions

?
Thank you
Simon Courtois - @happynoff
Ad

Recommended

PDF
Building WordPress Client Side Applications with WP and WP-API - #wcmia
Roy Sivan
ZIP
App engine beats pony.key
Alper Çugun
PDF
How to build Client Side Applications with WordPress and WP-API | #wcmia
Roy Sivan
PDF
Drupal8 Front-end Automated Testing
Ruben Teijeiro
PDF
Client Side Applications with WP-API WordPress - WCMTL 2015
Roy Sivan
PDF
Chef for the Symfony developer
Carlos Mafla
PPT
Services Apps Iand Flex Applications
Sumit Kataria
PPT
Object Oriented JavaScript
techwhizbang
PDF
WTF is PWA?
Alan Semenov
PPT
Introduccion app engine con python
sserrano44
PPTX
Angular js full stack development
Darius Riggins
PDF
Padre user experience
Charlie Gonzalez
PPT
symfony & jQuery (phpDay)
Massimiliano Arione
PPTX
Javascript async / await Frontend-IL
Ran Wahle
PDF
CPAN Dependency Heaven
OpusVL
PDF
Deployments... from dreaded to delightful.
Ryan King
ODP
Perl ides
Naim Shafiev
PPTX
php tutorial - By Bally Chohan
ballychohanuk
PDF
Redirect subdomain to webmail
Kaviyarasu Pugaz
PDF
Testing Microservices with a Citrus twist
christophd
PPT
Drupal site translation and translation testing
james_andres
PDF
Connect front end to back end using SignalR and Messaging
Particular Software
KEY
JavaScript Testing VIA Selenium
Adam Christian
PDF
Things I Heart
Glen Barnes
PDF
Laravel Forge: Hello World to Hello Production
Joe Ferguson
PDF
React Component Wars
Eyal Eizenberg
PPTX
9. lower in Symfony 4
Razvan Raducanu, PhD
PDF
Conseils pour un lancement Product Hunt réussi
Simon Courtois
PDF
Organize your assets with Rails
Simon Courtois

More Related Content

What's hot (20)

PDF
WTF is PWA?
Alan Semenov
PPT
Introduccion app engine con python
sserrano44
PPTX
Angular js full stack development
Darius Riggins
PDF
Padre user experience
Charlie Gonzalez
PPT
symfony & jQuery (phpDay)
Massimiliano Arione
PPTX
Javascript async / await Frontend-IL
Ran Wahle
PDF
CPAN Dependency Heaven
OpusVL
PDF
Deployments... from dreaded to delightful.
Ryan King
ODP
Perl ides
Naim Shafiev
PPTX
php tutorial - By Bally Chohan
ballychohanuk
PDF
Redirect subdomain to webmail
Kaviyarasu Pugaz
PDF
Testing Microservices with a Citrus twist
christophd
PPT
Drupal site translation and translation testing
james_andres
PDF
Connect front end to back end using SignalR and Messaging
Particular Software
KEY
JavaScript Testing VIA Selenium
Adam Christian
PDF
Things I Heart
Glen Barnes
PDF
Laravel Forge: Hello World to Hello Production
Joe Ferguson
PDF
React Component Wars
Eyal Eizenberg
PPTX
9. lower in Symfony 4
Razvan Raducanu, PhD
WTF is PWA?
Alan Semenov
Introduccion app engine con python
sserrano44
Angular js full stack development
Darius Riggins
Padre user experience
Charlie Gonzalez
symfony & jQuery (phpDay)
Massimiliano Arione
Javascript async / await Frontend-IL
Ran Wahle
CPAN Dependency Heaven
OpusVL
Deployments... from dreaded to delightful.
Ryan King
Perl ides
Naim Shafiev
php tutorial - By Bally Chohan
ballychohanuk
Redirect subdomain to webmail
Kaviyarasu Pugaz
Testing Microservices with a Citrus twist
christophd
Drupal site translation and translation testing
james_andres
Connect front end to back end using SignalR and Messaging
Particular Software
JavaScript Testing VIA Selenium
Adam Christian
Things I Heart
Glen Barnes
Laravel Forge: Hello World to Hello Production
Joe Ferguson
React Component Wars
Eyal Eizenberg
9. lower in Symfony 4
Razvan Raducanu, PhD

More from Simon Courtois (16)

PDF
Conseils pour un lancement Product Hunt réussi
Simon Courtois
PDF
Organize your assets with Rails
Simon Courtois
PDF
Speed your Rails app creation with templates
Simon Courtois
PDF
Dependency sorting in Ruby with TSort
Simon Courtois
PDF
How Unidecoder Transliterates UTF-8 to ASCII
Simon Courtois
PDF
Get Slim!
Simon Courtois
PDF
Fake your files - MemFs
Simon Courtois
PDF
Rails is like Burger King
Simon Courtois
PDF
REST with Her (and let Her take care of the REST)
Simon Courtois
PDF
Ruby and DCI
Simon Courtois
PDF
Mustdown
Simon Courtois
PDF
Vos Regexps sont fausses !
Simon Courtois
PDF
Pourquoi Ruby on Rails ça déchire ?
Simon Courtois
ZIP
Commander
Simon Courtois
Conseils pour un lancement Product Hunt réussi
Simon Courtois
Organize your assets with Rails
Simon Courtois
Speed your Rails app creation with templates
Simon Courtois
Dependency sorting in Ruby with TSort
Simon Courtois
How Unidecoder Transliterates UTF-8 to ASCII
Simon Courtois
Fake your files - MemFs
Simon Courtois
Rails is like Burger King
Simon Courtois
REST with Her (and let Her take care of the REST)
Simon Courtois
Ruby and DCI
Simon Courtois
Vos Regexps sont fausses !
Simon Courtois
Pourquoi Ruby on Rails ça déchire ?
Simon Courtois
Ad

Recently uploaded (20)

PPTX
Curietech AI in action - Accelerate MuleSoft development
shyamraj55
PDF
Quantum AI: Where Impossible Becomes Probable
Saikat Basu
PDF
AI Agents and FME: A How-to Guide on Generating Synthetic Metadata
Safe Software
PPTX
OpenACC and Open Hackathons Monthly Highlights June 2025
OpenACC
PDF
The Growing Value and Application of FME & GenAI
Safe Software
PDF
"Database isolation: how we deal with hundreds of direct connections to the d...
Fwdays
PDF
A Constitutional Quagmire - Ethical Minefields of AI, Cyber, and Privacy.pdf
Priyanka Aash
PDF
Quantum AI Discoveries: Fractal Patterns Consciousness and Cyclical Universes
Saikat Basu
PDF
9-1-1 Addressing: End-to-End Automation Using FME
Safe Software
PDF
From Manual to Auto Searching- FME in the Driver's Seat
Safe Software
PPTX
Security Tips for Enterprise Azure Solutions
Michele Leroux Bustamante
PDF
Hyderabad MuleSoft In-Person Meetup (June 21, 2025) ݺߣs
Ravi Tamada
PDF
"Scaling in space and time with Temporal", Andriy Lupa.pdf
Fwdays
PDF
Salesforce Summer '25 Release Frenchgathering.pptx.pdf
yosra Saidani
PDF
Agentic AI for Developers and Data Scientists Build an AI Agent in 10 Lines o...
All Things Open
PDF
Database Benchmarking for Performance Masterclass: Session 2 - Data Modeling ...
ScyllaDB
PDF
Tech-ASan: Two-stage check for Address Sanitizer - Yixuan Cao.pdf
caoyixuan2019
PDF
Mastering AI Workflows with FME by Mark Döring
Safe Software
PDF
GenAI Opportunities and Challenges - Where 370 Enterprises Are Focusing Now.pdf
Priyanka Aash
PDF
Enhance GitHub Copilot using MCP - Enterprise version.pdf
Nilesh Gule
Curietech AI in action - Accelerate MuleSoft development
shyamraj55
Quantum AI: Where Impossible Becomes Probable
Saikat Basu
AI Agents and FME: A How-to Guide on Generating Synthetic Metadata
Safe Software
OpenACC and Open Hackathons Monthly Highlights June 2025
OpenACC
The Growing Value and Application of FME & GenAI
Safe Software
"Database isolation: how we deal with hundreds of direct connections to the d...
Fwdays
A Constitutional Quagmire - Ethical Minefields of AI, Cyber, and Privacy.pdf
Priyanka Aash
Quantum AI Discoveries: Fractal Patterns Consciousness and Cyclical Universes
Saikat Basu
9-1-1 Addressing: End-to-End Automation Using FME
Safe Software
From Manual to Auto Searching- FME in the Driver's Seat
Safe Software
Security Tips for Enterprise Azure Solutions
Michele Leroux Bustamante
Hyderabad MuleSoft In-Person Meetup (June 21, 2025) ݺߣs
Ravi Tamada
"Scaling in space and time with Temporal", Andriy Lupa.pdf
Fwdays
Salesforce Summer '25 Release Frenchgathering.pptx.pdf
yosra Saidani
Agentic AI for Developers and Data Scientists Build an AI Agent in 10 Lines o...
All Things Open
Database Benchmarking for Performance Masterclass: Session 2 - Data Modeling ...
ScyllaDB
Tech-ASan: Two-stage check for Address Sanitizer - Yixuan Cao.pdf
caoyixuan2019
Mastering AI Workflows with FME by Mark Döring
Safe Software
GenAI Opportunities and Challenges - Where 370 Enterprises Are Focusing Now.pdf
Priyanka Aash
Enhance GitHub Copilot using MCP - Enterprise version.pdf
Nilesh Gule
Ad

Multi tenant/lang application with Ruby on Rails