Custom types and assets for tenants in an application with multiple tenants?

When using the rails engine, redefining views is as simple as creating new views in the right folder. But when creating an application for multi-level rails, where all tenants are in the same application (they do not use the engine), how can you redefine the views for tenants.

For instance:

The application has a file views/static/about_us.haml , which must be configured for each tenant. What is the best way to override this file for each tenant?

+6
source share
1 answer

I use the gem of an apartment , which is good for managing multi-tenant environments. The apartment helps you manage schematic databases and helps you with migration.

The application uses the correct scheme depending on the subdomain. For example, in the case of superclient.mysuperapp.com, the rails will use the superclass database schema and will only work on this schema until the request completes.

For multitenant views , in my case, I use before_action in ApplicationController.rb to prepend my custom view path:

 def prepend_view_paths subdomain = request.subdomain prepend_view_path "app/views/multitenancy/#{subdomain}" end 

Where the subdomain in this case is a superclient.

The logic is this: first, the rails will look for an idea along this path: "app / views / multitenancy / # {subdomain}". And if he does not find anything, he continues to find representation in other ways in the list.

Hope my answer helps you.

+1
source

Source: https://habr.com/ru/post/988693/


All Articles