1
我使用公寓和设计创业板穆蒂租户和认证。设计:登录用户,并重定向到子域
我在根域URL(example.com
)中有一个sign_up
页面,我从中获取用户的子域详细信息。
我需要sign_in
用户成功保存记录并重定向到新的子域(sub.example.com
)。
公寓架构:
帐户=>通用于所有模式(公共)
用户=> seperately会为每个模式(私人)
这个RegistrationController:
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
到新的子域。
谢谢。
是否重定向到'root_url'保留会话cookie? – 31piy
@ 31piy,我试图消除在root_url认证,并试图在打印控制器动作会议'p会话[“warden.user.user.key”]',但它返回'nil' –
请检查会话ID之前相同并在重定向之后。 – 31piy