我有两个设计模型,这很好,因为它们捕获了不同的价值,我觉得分离它们是最好的解决方案,而不是使用角色。
话虽如此,我正试图根植于不同的观点。这是我的路由文件:
devise_for :patients, controllers: {
sessions: 'patients/sessions',
registrations: 'patients/registrations'
}
as :patient do
authenticated do
root to: 'dashboard#patient'
end
unauthenticated do
root to: 'shared#home', as: 'unauthenticated_root'
end
end
devise_for :pharmacists, controllers: {
sessions: 'pharmacists/sessions',
registrations: 'pharmacists/registrations'
}
as :pharmacist do
authenticated do
root to: 'dashboard#pharmacist'
end
unauthenticated do
root to: 'shared#home', as: 'unauthenticated_root'
end
end
以下是错误消息:
Invalid route name, already in use: 'root'
You may have defined two routes with the same name using the `:as` option,
or you may be overriding a route already defined by a resource with the
same naming.
缓解这个问题的最好方法是什么?
发布于 2015-09-11 06:34:16
这个问题源于这样一个事实:我没有在实际的root上使用"as:“,所以它们最终具有相同的端点。修复此问题后,正确的代码如下所示:
devise_for :patients, controllers: {
sessions: 'patients/sessions',
registrations: 'patients/registrations'
}
devise_scope :patient do
authenticated do
root to: 'dashboard#patient', as: 'authenticated_patient_root'
end
unauthenticated do
root to: 'shared#home', as: 'unauthenticated_patient_root'
end
end
devise_for :pharmacists, controllers: {
sessions: 'pharmacists/sessions',
registrations: 'pharamacists/registrations'
}
devise_scope :pharmacist do
authenticated do
root to: 'dashboard#pharmacist', as: 'authenticated_pharmacist_root'
end
unauthenticated do
root to: 'shared#home', as: 'unauthenticated_pharmacist_root'
end
end
发布于 2018-06-09 08:22:18
在没有devise_scope
的情况下,您可以使用下面的hack实现相同的功能
authenticated :patient do
root to: "patients#show", as: :authenticated_patient
end
authenticated :pharmacist do
root "pharmacists#index", as: :authenticated_pharmacist
end
unauthenticated do
root "pages#home", as: :unauthenticated_user
end
https://stackoverflow.com/questions/32511298
复制相似问题