【发布时间】:2020-12-21 05:25:16
【问题描述】:
Rails 5, apartment gem
动作线connection.rb
module ApplicationCable
class Connection < ActionCable::Connection::Base
identified_by :current_user, :tenant
def connect
self.tenant = request.subdomain
Apartment::Tenant.switch!(tenant)
self.current_user = find_verified_user
logger.add_tags 'ActionCable', current_user.try(:email) || 'Unauthenticated User'
end
protected
def find_verified_user # this checks whether a user is authenticated with devise
if verified_user = env['warden'].user
verified_user
else
# May have public users accessing the channels
# reject_unauthorized_connection
end
end
end
end
environments/production.rb
config.action_cable.allowed_request_origins = [ /https:\/\/(.*).mydomain.com/ ]
尝试了从这些链接中获取的上述代码参考:Link 1 和 Link 2,但无法正常工作。
在生产中:request.subdomain 是 nil(尝试对一些租户值进行热编码,但不起作用)
开发中:request.subdomain 提供租户名称,但实际请求不起作用。
有什么帮助吗?
【问题讨论】:
标签: ruby-on-rails actioncable apartment-gem