Ruby on rails 登录后将用户定向到其各自的子域
我的用户可以注册应用程序,并被引导到他们在屏幕中键入的相应子域。我希望在重新登录时将它们重定向回同一子域。我没有收到一个错误,但当我在系统中重新登录时,不会在url前面插入子域 应用程序\u controller.rbRuby on rails 登录后将用户定向到其各自的子域,ruby-on-rails,ruby,devise,apartment-gem,Ruby On Rails,Ruby,Devise,Apartment Gem,我的用户可以注册应用程序,并被引导到他们在屏幕中键入的相应子域。我希望在重新登录时将它们重定向回同一子域。我没有收到一个错误,但当我在系统中重新登录时,不会在url前面插入子域 应用程序\u controller.rb skip_before_action :verify_authenticity_token def after_sign_in_path_for(resource_or_scope) root_url(:subdomain => resource.subdomain)
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
routes.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
在您的第一个代码块中,
resource\u或\u scope
的值是多少?如果您在应用程序中创建了一个RegistrationController
,您可以在为(资源)在路径中进行签名后使用,或者您可以将其添加到应用程序控制器中,并告诉设计
用户登录时将发送到何处(如果您使用设计gem
)是否可能是因为我使用的是帐户控制器让我的用户注册?而不是标准注册控制器。。。