[英]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. 该
favorties
, tours
, offers
和open_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.