我在添加斜线段和嵌套路由时遇到问题。
如果我有这些路线:
resources :courses do
resources :registrations
end
我有这些网址:
/courses/7
/courses/7/registrations
如果我在 Course.rb 中更改 to_param,我会在路线中遇到一些问题:
def to_param
"#{id}-#{slug}"
end
这给了我:
/courses/7-title-of-course
/courses/7-title-of-course/registrations
到目前为止一切都很好。
我遇到的问题是看了这个http://www.miguelsanmiguel.com/2011/03/17/slug-that-slash:
如何让它与嵌套资源一起使用:
课程.rb:
def to_param
"#{id}/#{slug}"
end
路由.rb
resources :courses, :constraints => { :id => /[0-9]+\/.+/ } do
resources :registrations
end
网址:
/courses/7/title-of-course
/courses/7/title-of-course/registrations
如果我这样设置课程路线很好,但注册路线被破坏了。
这里有什么提示吗?