ErwinM / acts_as_tenant

Easy multi-tenancy for Rails in a shared database setup.
MIT License
1.53k stars 263 forks source link

Accessing current_tenant within Rails router #256

Closed DavidGeismarLtd closed 3 years ago

DavidGeismarLtd commented 3 years ago

I have setup acts_as_tenant to set the current_tenant based on the current subdomain in my ApplicationController :

class ApplicationController < ActionController::Base
  set_current_tenant_by_subdomain(:account, :subdomain)

I need to open or close some routes based on some attribute value in the current_tenant instance. However current_tenant is not directly accessible in the rails router. Is there a clean way to circumvent that ? Has the gem put in place any mechanism for that scenario ?

excid3 commented 3 years ago

The tenant doesn't get detected until the controller. You'd have to build a custom route constraint to detect it during routing.

DavidGeismarLtd commented 3 years ago

thanks, I did just that !