rails资源路由中的默认段名称
我想在我的rails应用程序中创建一条路线
/panda/blog /tiger/blog /dog/blog
pandas,老虎和狗都是永久性的(动物类)
这样做的正常方式
map.resources :animals do |animal| animal.resource :blog end
会沿着线路创建路线
/animals/panda/blog /animals/tiger/blog /animals/dog/blog
但我不想要第一段,因为它总是一样的。
我知道我可以通过手动路由来做到这一点,但我想知道如何使用rails资源,因为有动物和博客是我的要求。
在rails 3.x中,您可以将path => ""
添加到任何resource
或resources
调用,以从生成的路径中删除第一个段。
resources :animals, :path => ""
$ rake routes animals GET / {:action=>"index", :controller=>"animals"} POST / {:action=>"create", :controller=>"animals"} new_animal GET /new(.:format) {:action=>"new", :controller=>"animals"} edit_animal GET /:id/edit(.:format) {:action=>"edit", :controller=>"animals"} animal GET /:id(.:format) {:action=>"show", :controller=>"animals"} PUT /:id(.:format) {:action=>"update", :controller=>"animals"} DELETE /:id(.:format) {:action=>"destroy", :controller=>"animals"}