使用设计和子域约束进行Rails路由

时间:2017-09-10 07:19:27

标签: ruby-on-rails ruby devise routes ruby-on-rails-5

我正在尝试将root路由到subdomain约束下的路径设计。

我的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

我收到错误Could not find devise mapping for path "/".

关于如何在具有设计范围的子域中路由到根路径的任何建议?

由于

1 个答案:

答案 0 :(得分:1)

要向路由添加身份验证约束,请使用设计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