【问题标题】:allow only access route when its nested RoR仅在嵌套 RoR 时允许访问路由
【发布时间】:2014-02-25 13:53:58
【问题描述】:

我是 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) 

【问题讨论】:

  • 请阅读更多关于胭脂guides.rubyonrails.org/routing.html的信息。对你有很大帮助。
  • 我正在这样做,但我的代码中还有其他问题。我解决了它,现在从根作品中否认......

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


【解决方案1】:
resources :trips
  resources :destinations
end

如果您执行上述操作,它将拒绝root/destination,但将允许root/trip/:id/destination

【讨论】:

  • 好的,谢谢...这有帮助。现在我无法从根访问目的地!
猜你喜欢
  • 2013-08-14
  • 2011-07-16
  • 2019-03-10
  • 2017-10-02
  • 2020-01-01
  • 1970-01-01
  • 2016-10-07
  • 2012-04-14
  • 2013-12-30
相关资源
最近更新 更多