acts_as_tenant
acts_as_tenant copied to clipboard
Add support for setting the current tenant in an ActionCable context
Allows you to use set_current_tenant_through_filter
, set_current_tenant_by_subdomain_or_domain
and set_current_tenant_by_subdomain
in ActionCable channels, in a similar vein as ActionControllers.
E.g.:
class SpecSubdomainOrDomainChannel < ApplicationCable::Channel
set_current_tenant_by_subdomain_or_domain
def subscribed
reject if params[:room_id].nil?
end
def whoami
transmit current_tenant.name
end
end
Haven't made any changes to the README, as I wasn't sure where to put it :)
@scarhand Looks like ActiveSupport.on_load(:action_cable_channel)
wasn't added until Rails 6, which is the cause for the failures on Rails 5.2.
Rails 5.2 is EOL on June 1st, 2022, so we can't really drop support for it yet I feel like.
Maybe we can do a different method for Rails 5, like a config.to_prepare
block or something?
Looks like the PR is about a month too early then ;)
I'll see if config.to_prepare
can be used, or if there's something else that works with Rails 5(.2).
If there's nothing easy, we can wait on Rails 5.2 to be EOL and update the required versions here soon.