Published on March 4, 2014
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
Thank you Simon Courtois - @happynoff
Learning to build a modern web application is daunting. Ruby on Rails makes it much easier and more fun. ... Ruby on Rails is open source software, ...
Multitenancy with Rails ... tricks about Rails and PostgreSQL while you build a multi-tenanted Ruby on Rails application. What's a multi-tenanted ...
I originally wrote my Ruby on Rails application for one client. ... Any advice related to multi-tenant applications or my situation is welcome.
I have created a multitenant Ruby on Rails application. Each tenant will configure their domain name to my server's ip and then they can navigate to their ...
Getting Started with Rails. ... Rails is a web application framework running on the Ruby programming language. If you have no prior experience with Ruby, ...
The Ruby Toolbox is a comprehensive catalog of Ruby and Rails plug-ins, ... Rails multitenancy with ... Integrates multi-tenancy into Rail application with ...
Office Productivity. Office Productivity. Microsoft; Apple; Google; SAP; Intuit ... Personal Development
Creating a SAAS application in Ruby on Rails is ... I have documented the whole process in a course called Creating a multi tenant SAAS app in Ruby on Rails.
Form Helpers. Forms in web applications are an essential ... The previous sections did not use the Rails form helpers at ... "Ruby on Rails", ...