I am trying to change the controller and action of users
model in routing.rb
when pointed at /users
url. 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. But when calling the /user/:id
, it doesn't map to routers
controller. 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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.