Ruby Rails 5使用Desive并充当租户
我有一个应用程序正在使用Desive处理登录/注册。我还使用acts_作为_租户。我需要确保每次有人注册/登录时都设置了租户。要使“作为租户的行为”正常工作,必须在身份验证之前设置租户。现在我在我的ApplicationController上使用before_操作,但问题是即使有人拥有无效的凭据等,也会调用该方法,并且我试图避免在方法中写入if语句来确定我是否拥有有效的用户Ruby Rails 5使用Desive并充当租户,ruby,devise,acts-as-tenant,Ruby,Devise,Acts As Tenant,我有一个应用程序正在使用Desive处理登录/注册。我还使用acts_作为_租户。我需要确保每次有人注册/登录时都设置了租户。要使“作为租户的行为”正常工作,必须在身份验证之前设置租户。现在我在我的ApplicationController上使用before_操作,但问题是即使有人拥有无效的凭据等,也会调用该方法,并且我试图避免在方法中写入if语句来确定我是否拥有有效的用户 实现这一目标的最佳方式是什么?任何处于类似情况的人?如果您需要在使用Desive进行身份验证之前设置租户,则需要使用act
实现这一目标的最佳方式是什么?任何处于类似情况的人?如果您需要在使用Desive进行身份验证之前设置租户,则需要使用
acts\u as\u租户
的手动租户设置方法,以便控制时间
# application_controller.rb
class ApplicationController < ActionController::Base
protect_from_forgery with: :exception
# tell acts_as_tenant you'll manually set the tenant
set_current_tenant_through_filter
# manually set the tenant before Devise auth
prepend_before_action :set_current_tenant_by_subdomain
# Devise auth as usual but after tenant is set
before_action :authenticate_user!
private
def set_current_tenant_by_subdomain
current_organization = Organization.find_by_subdomain(request.subdomain)
set_current_tenant(current_organization)
end
end
#应用程序_controller.rb
类ApplicationController