Ruby on rails 4 登录后重定向到子域

Ruby on rails 4 登录后重定向到子域,ruby-on-rails-4,devise,subdomain,url-redirection,Ruby On Rails 4,Devise,Subdomain,Url Redirection,我正在使用Desive进行身份验证,开发一个多延迟应用程序。子域的使用对于此构建非常关键 目前,我的设置包括强制用户“记住”他们的子域,以便他们可以登录 路线 constraints(SubdomainPresent) do root 'users#index', as: :subdomain_root resources :users resources :accounts end devise_for :users 我想实现的是与我的用户首次注册时发生的非常类似的事情,即一旦

我正在使用Desive进行身份验证,开发一个多延迟应用程序。子域的使用对于此构建非常关键

目前,我的设置包括强制用户“记住”他们的子域,以便他们可以登录

路线

constraints(SubdomainPresent) do
  root 'users#index', as: :subdomain_root
  resources :users
  resources :accounts
end

devise_for :users
我想实现的是与我的用户首次注册时发生的非常类似的事情,即一旦保存,他们将重定向到其子域以登录(url结构反映了这一点)subdomain.example.com

客户控制员

if @account.valid?
  Apartment::Tenant.create(@account.subdomain)
  Apartment::Tenant.switch(@account.subdomain)
  @account.save

  format.html { redirect_to new_user_session_url(subdomain: @account.subdomain), notice: 'Account was successfully created.' }

我想使用它,这样我的用户就可以从站点上的任何位置、非子域位置登录,并让它将他们重定向到正确的dashbaord和子域url结构

您可以覆盖的注册后路径方法,并使用类似以下内容:

  def after_sign_up_path_for(resource)
     edit_user_registration_url(:subdomain => resource.subdomain)
  end

仅供参考,
重定向到root\u url(子域:“新客户”)
也可以。