简体   繁体   English

如何在Rails的根目录更改模型的默认路由?

[英]How to change the default routing of a model at root in rails?

I am trying to change the controller and action of users model in routing.rb when pointed at /users url. 当试图指向/users url时,我试图在routing.rb更改users模型的控制器和操作。 Here is how I tried to change it: 这是我尝试更改的方法:

resources :users, only: :show do
    get 'favorites' => 'routers#client'
    get 'tours' => 'routers#client'
    get 'offers' => 'routers#client'
    get 'open_houses' => 'routers#client'
    get 'searches'
end
get 'users/:id' => 'routers#client'

The favorties , tours , offers and open_houses route to routers_controller client action when url such as /users/:id/favorites etc are called. favortiestoursoffersopen_houses路由routers_controller client操作时的URL,如/users/:id/favorites等被调用。 But when calling the /user/:id , it doesn't map to routers controller. 但是,当调用/user/:id ,它不会映射到routers控制器。 How should I change the index route to this controller? 我应该如何更改到该控制器的索引路由?

Finally found it through hit and trial. 终于通过命中和尝试找到了它。 To route the index, we can do 要路由索引,我们可以做

resources :users, only: :show do
    get '' => 'routers#client'
    get 'favorites' => 'routers#client'
    get 'tours' => 'routers#client'
    get 'offers' => 'routers#client'
    get 'open_houses' => 'routers#client'
    get 'searches'
end

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

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