Rails 一个路由设计的问题

kitaro000 · November 18, 2015 · Last by night_7th replied at November 23, 2015 · 1743 hits

比如涉及两个资源:书、作者 我希望能从不同的路径定位到作者

resources :books do
  resources :authors
end

resources :authors

这样有可能吗?

可以用 Shallow Nesting

resources :books do
  resources :authors, shallow: true
end

参考 2.7.2 Shallow Nesting http://guides.rubyonrails.org/routing.html

我也遇到了同样的问题,你现在这样的写法其实已经可以了。可以用except排除掉多余的路由。

Shallow Nesting 是把index, new, create这三个 action 变为嵌套路由,剩下的不用嵌套。和我的需求稍稍有些差异。

You need to Sign in before reply, if you don't have an account, please Sign up first.