首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >使用2个设计模型的多个"root to“

使用2个设计模型的多个"root to“
EN

Stack Overflow用户
提问于 2015-09-11 04:45:20
回答 2查看 1.1K关注 0票数 1

我有两个设计模型,这很好,因为它们捕获了不同的价值,我觉得分离它们是最好的解决方案,而不是使用角色。

话虽如此,我正试图根植于不同的观点。这是我的路由文件:

代码语言:javascript
复制
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

以下是错误消息:

代码语言:javascript
复制
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.

缓解这个问题的最好方法是什么?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2015-09-11 06:34:16

这个问题源于这样一个事实:我没有在实际的root上使用"as:“,所以它们最终具有相同的端点。修复此问题后,正确的代码如下所示:

代码语言:javascript
复制
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
票数 3
EN

Stack Overflow用户

发布于 2018-06-09 08:22:18

在没有devise_scope的情况下,您可以使用下面的hack实现相同的功能

代码语言:javascript
复制
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
票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32511298

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档