我正在使用Apartment and Devise gem 进行多租户和身份验证。
我sign_up在根域 URL( example.com) 中有一个页面,可以从用户那里获取子域详细信息。
sign_in成功保存记录并重定向到新的子域(sub.example.com)后,我需要用户。
公寓模式:
帐户 => 所有模式的通用(公共)
用户 => 为每个模式单独创建(私有)
注册控制器:
class Users::RegistrationsController < Devise::RegistrationsController
...
...
def create
ActiveRecord::Base.transaction do
@account = Account.new(account_params)
if @account.valid?
# Create & switch to the new tenant
Apartment::Tenant.create(@account.subdomain)
Apartment::Tenant.switch!(@account.subdomain)
@account.save
sign_in(:user, @account.user)
redirect_to root_url(subdomain: "#{Apartment::Tenant.current}")
else
render :action => 'new'
end
end
end
...
...
protected
def account_params
params.require(:account).permit(:name, :subdomain, user_attributes: [:first_name, :last_name, :email, :password, :password_confirmation])
end
end
上面的代码成功地重定向到了新的子域,但是,虽然我在重定向之前正在登录用户,但它不是用户登录。
请任何人帮助我将用户重定向signed_in到新的子域。
谢谢..