使用Rails的设计和子域约束
我试图航线根制定登录路径下的subdomain
约束路由。使用Rails的设计和子域约束
我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 "/".
任何建议,我怎么路线根路径与色器件范围域名?
感谢
要添加限制给路由的认证用色器件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
'devise_scope'真的只是scope'的'有一项版本,安装在色器件路径路由。 'devise_scope:users'会将路径挂载到'/ users'中。 – max
感谢您的回复。我们只能从'devise_scope'内部设计控制器。我尝试使用'unauthenticated'来路由到根目录,但它仍然显示相同的错误消息。有没有一种方法,我可以'devise_scope'路线,并覆盖缺省值,同时指定'根:“设计/会话#new''? –
它的工作原理类似: '根:“设计/会话#新”,约束: {subdomain:'admin'}' –
感谢您的跟进。我仍然需要将它放在'devise_scope'块中,从而覆盖默认的设计路线。要做到这一点,我已经把它放在一个“约束”块内。不知何故,我仍然无法从那里访问'devise'控制器。 –