Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/61.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 登录后将用户定向到其各自的子域_Ruby On Rails_Ruby_Devise_Apartment Gem - Fatal编程技术网

Ruby on rails 登录后将用户定向到其各自的子域

Ruby 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)

我的用户可以注册应用程序,并被引导到他们在屏幕中键入的相应子域。我希望在重新登录时将它们重定向回同一子域。我没有收到一个错误,但当我在系统中重新登录时,不会在url前面插入子域

应用程序\u 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 
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
)是否可能是因为我使用的是帐户控制器让我的用户注册?而不是标准注册控制器。。。