Project

tenanfy

0.0
No commit activity in last 3 years
No release in over 3 years
Offers a opinated use of the Apartment gem.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

>= 0.25.0
>= 3.2.0
 Project Readme

Tenanfy¶ ↑

This is opinionated use of the awesome Apartment gem. It’s a plug and play ready solution for enabling multitenancy in rails applications. It comes with configurations and helpers I find usefull in my projects.

Apartment is an awesome gem by itself, be sure to read more about it at github.com/bradrobertson/apartment

How¶ ↑

If you don’t know what is tenantcy or how the apartment gem works, please read github.com/bradrobertson/apartment first.

This gem creates 2 models, Tenanfy::[Tenant, Url]. When you include the Tenanfy::Controller to your controller, it will automatically check for the correct Tenant for each request. This is done by looking for the request.host in the Tenanfy::Url table. The current tenant will be available in the ‘current_tenant` method.

This is meant to be used and only tested using PostgreSQL. Every tenant will have it own schema in the database, and the apartment gem will use postgres’ awesome ‘search_path` to look in the current_tenant schema first. You may have shared tables between your tenants, check the `config/initializers/apartment.rb`.

Why¶ ↑

If you don’t need any of this customizations, I recommend you use the Apartment gem alone. I only made this because I had these requirements in more than one project, and maybe someone could find a good use of it too.

Customizations¶ ↑

Custom Views per tenant¶ ↑

In my projects, each tenant usually have a different layout/theme. So the tenant model have a ‘theme` attribute. When this is setted, the `Tenanfy::Controller` will prepend the tenant theme in the view path, for example, if the theme is `blue`, the path `app/views/blue` will be prepended to the controller view_path.

Custom JS/CSS per tenant¶ ↑

There are helpers to include the javascripts/stylesheets with the tenant theme (ex: app/assets/javascripts/blue/application.js).

Example:

<%= tenant_stylesheet_link_tag('application.css') %>   # will include blue/application.css
<%= tenant_javascript_include_tag('application.js') %> # will include blue/application.js

Installation¶ ↑

Gemfile:

gem 'tenanfy'

Console:

rails g tenanfy:install
rake db:migrate

License¶ ↑

This project uses MIT-LICENSE.