我的用户能够注册该应用程序并被定向到他们在屏幕中键入的相应子域。我希望在重新登录时将它们重定向回同一个子域。我没有收到任何错误,但是当我重新登录系统时,不会在 url 前面插入子域。
application_controller.rb
skip_before_action :verify_authenticity_token
def after_sign_in_path_for(resource_or_scope)
root_url(:subdomain => resource.subdomain)
end
def after_sign_out_path_for(resource_or_scope)
root_url(subdomain: false)
end
路线.rb
class SubdomainPresent
def self.matches?(request)
subdomains = %w{ www admin }
request.subdomain.present? && !subdomains.include?(request.subdomain)
end
end
class SubdomainBlank
def self.matches?(request)
request.subdomain.blank?
end
end
Rails.application.routes.draw do
resources :accounts
devise_for :users, controllers: { registrations: 'accounts', sessions: 'sessions' }
get 'contact-us', to: 'contacts#new', as: 'new_contact'
constraints(SubdomainBlank) do
root 'visitors#new'
get 'about', to: 'pages#about'
get 'services', to: 'pages#services'
resources :contacts, only: :create
resources :visitors, only: [:new, :create]
end
constraints(SubdomainPresent) do
root 'tasks#index', as: :subdomain_root
resources :users do
resource :profile
end
resources :tasks
resources :deals
resources :companies
end
end