只允许在嵌套RoR时访问路由

时间:2014-02-25 13:53:58

标签: ruby-on-rails routes nested-resources

我是RoR的新手,我在这里挣扎着路线。我需要的是允许我的应用程序获取这样的路线:

root/trip/:id/destination

但拒绝这样的路线:

root/destination

我的路线文件如下:

resources :destinations
  resources :trips do
    resources :destinations
  end
  root to: "trips#index"

当我从路线中取出第一行而不是嵌套链接时。我想要完成的是从

开始
-> /root/trip(with linke to new file with new view) 
-> /root/show_all_destinations (with its own index and show action) and than 
-> /root/show_all_destination/:id (without edit/new/delete) 

1 个答案:

答案 0 :(得分:0)

resources :trips
  resources :destinations
end

如果您喜欢上述内容,则会拒绝root/destination,但会允许root/trip/:id/destination