简体   繁体   English

将根路径设置为嵌套路由,具体取决于用户的角色Rails 5

[英]Set root path to a nested route, depending on role of users Rails 5

In my app, if a signed in user is a Borrower, I want them to be routed to bank/:id/documents . 在我的应用程序中,如果登录的用户是借款人,我希望将他们路由到bank/:id/documents I'm not sure how to setup the nested resource here. 我不确定如何在此处设置嵌套资源。

I'd like to have something like this: 我想要这样的东西:

 authenticated :user, lambda { |u| u.role == :teller } do
        root to: 'banks#index', :as => :teller_root
  end

  authenticated :user, lambda { |u| u.role == :borrower } do
    root to: 'banks/:id/documents', :as => :borrower_root
  end

The first route works, but I don't know how to route the second one. 第一条路线可行,但我不知道如何布置第二条路线。 It's basically just a random attempt to give you an idea of what I'm trying to do. 基本上,这只是一个随机尝试,目的是让您了解我要做什么。

I created a RootsController and in its index action added logic to decide what the root path should be. 我创建了一个RootsController并在其index动作中添加了逻辑以决定根路径应该是什么。 And then in my routes file I just set root to root :to => "roots#index . This appears to work. 然后在我的路由文件中,我将root设置为root :to => "roots#index 。这似乎起作用。

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

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