简体   繁体   English

使用devise和子域约束的​​Rails路由

[英]Rails routing using devise and subdomain constraint

I am trying to route root to devise sign in path under a subdomain constraint. 我试图在subdomain约束下路由root来设计登录路径。

My config/routes.rb look something like this 我的config/routes.rb看起来像这样

Rails.application.routes.draw 
  constraints subdomain: 'admin' do
    devise_scope :admin do
      root to: 'devise/sessions#new'

      # here I override devise routes
    end
  end

  root to: 'pages#homepage'

  # rest of the routes  
end

I am getting the error Could not find devise mapping for path "/". 我收到错误消息Could not find devise mapping for path "/".

Any suggestions as to how I route to root path in a subdomain with devise scope? 关于如何路由到具有设计范围的子域中的根路径的任何建议?

Thanks 谢谢

To add an authentication constrain to a route use the devise authenticated method: 要向路由添加身份验证约束,请使用devise authenticated方法:

Rails.application.routes.draw 
  constraints subdomain: 'admin' do
    authenticated :admin do
      # the root page for authenticated users
      root 'admin#dashboard', as: :authenticated_root
    end
    root to: 'devise/sessions#new'
  end

  # this is for no subdomain
  root to: 'pages#homepage'
end

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM