(我正在练习 codeschool 的在线课程,rails 应用程序从头开始第 1 部分)
这是我的routes.rb
resources :destinations, only: :index
resources :trips do
resources :destinations
end
结果rake routes
使这两条路线执行相同的操作:
Prefix Verb URI Pattern Controller#Action
destinations GET /destinations(.:format) destinations#index
trip_destinations GET /trips/:trip_id/destinations(.:format) destinations#index
我希望匹配trip_destinations
到trip#show
,即重定向到/trips/:id
,我有一些解决方案,例如硬编码routes.rb
或添加重定向destination#index
。哪一个更好?是否有完成此任务的最佳实践?