Best way to customize CSS for tenants on a multi-tenant app?
Asked Answered
N

1

6

I'm using the Apartment gem to build a multi-tenant app (each tenant lives in a different Postgres schema).

What's the best way in Rails to define custom CSS overrides for each tenant?

Newcomen answered 7/6, 2015 at 4:19 Comment(3)
Where you your efforts?Henbane
I'm not asking for code. Just semantics on what's the "rails way" of doing this.Newcomen
You could have some key values a admin or a tenant can change on the DB. I like to call this table settings and the relationship would be setting belongs_to tenant. and tenant has_one setting.Eyetooth
H
1

Given that multi-tenancy is itself a deviation from the rails way of doing things, I am not sure there a definitive answer to be provided here.

I recommend the following approach, which I think fits well with your use case:

In your layout:

<html>
<head>
  <%= stylesheet_link_tag "tenant_#{@tenant_name}" %>
</head>
<body class="tenant-<%= @tenant_name %>">
</body> 
</html>

In your scss files:

For each tenant (say t1) you can have:

tenant_t1.css.scss

body.tenant-t1 {
  ... stylesheets specific to tenant 1 scoped within tenant-specific class ...
}
Harrington answered 25/10, 2015 at 8:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.