新手问题 路由中 only: [] 是什么意思

tardis · January 29, 2015 · Last by hmilym replied at February 08, 2015 · 7092 hits

在路由文件中

resources :res_1, only: [] do
    resources :res_2, only: [:index, show]
end

only:[] 是什么意思?

这个路由声明对应的 url 形式又是怎样的?

#1 楼 @night_7th 那 :res_1, only: [] 的意思是对 res_1 不生成任何路由?

3 Floor has deleted

这里其实是为了构造嵌套的形式,的确 res_1 本身不会生成路由,这种情况直接用 namespace 啊。

使用 resources 会生成 7 个路由,很多时候我们只需要其中的几个 action,可以用 only 来限制,使用 rake routes 查看就知道效果了。

rails 中很多地方有会有 only, except 设置,比如 route,before_action/after_action/around_action等等。

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