Resource Routing: short style
here is my config/routes.rb
:
Eesoudayo::Application.routes.draw do
resources :articles do
resources :comments
end
end
...which, as you can imagine, generates the following routes:
article_comments GET /articles/:article_id/comments(.:format) {:action=>"index", :controller=>"comments"}
开发者_Python百科 POST /articles/:article_id/comments(.:format) {:action=>"create", :controller=>"comments"}
new_article_comment GET /articles/:article_id/comments/new(.:format) {:action=>"new", :controller=>"comments"}
edit_article_comment GET /articles/:article_id/comments/:id/edit(.:format) {:action=>"edit", :controller=>"comments"}
article_comment GET /articles/:article_id/comments/:id(.:format) {:action=>"show", :controller=>"comments"}
PUT /articles/:article_id/comments/:id(.:format) {:action=>"update", :controller=>"comments"}
DELETE /articles/:article_id/comments/:id(.:format) {:action=>"destroy", :controller=>"comments"}
articles GET /articles(.:format) {:action=>"index", :controller=>"articles"}
POST /articles(.:format) {:action=>"create", :controller=>"articles"}
new_article GET /articles/new(.:format) {:action=>"new", :controller=>"articles"}
edit_article GET /articles/:id/edit(.:format) {:action=>"edit", :controller=>"articles"}
article GET /articles/:id(.:format) {:action=>"show", :controller=>"articles"}
PUT /articles/:id(.:format) {:action=>"update", :controller=>"articles"}
DELETE /articles/:id(.:format) {:action=>"destroy", :controller=>"articles"}
My question is: is there a sexy way to clean a little bit them, giving this result?
article_comments GET /:article_id/(.:format) {:action=>"index", :controller=>"comments"}
POST /:article_id/(.:format) {:action=>"create", :controller=>"comments"}
new_article_comment GET /:article_id/new(.:format) {:action=>"new", :controller=>"comments"}
edit_article_comment GET /:article_id/:id/edit(.:format) {:action=>"edit", :controller=>"comments"}
article_comment GET /:article_id/:id(.:format) {:action=>"show", :controller=>"comments"}
PUT /:article_id/:id(.:format) {:action=>"update", :controller=>"comments"}
DELETE /:article_id/:id(.:format) {:action=>"destroy", :controller=>"comments"}
articles GET /.:format) {:action=>"index", :controller=>"articles"}
POST /.:format) {:action=>"create", :controller=>"articles"}
new_article GET /new(.:format) {:action=>"new", :controller=>"articles"}
edit_article GET /:id/edit(.:format) {:action=>"edit", :controller=>"articles"}
article GET /:id(.:format) {:action=>"show", :controller=>"articles"}
PUT /:id(.:format) {:action=>"update", :controller=>"articles"}
DELETE /:id(.:format) {:action=>"destroy", :controller=>"articles"}
PS: I'm working with Rails 3.x <3
I don't really know if this works, a shot in the dark really:
Eesoudayo::Application.routes.draw do
resources :articles, :path => "/" do
resources :comments, :path => "/"
end
end
I have only tested this using rake routes
, it may very well be that everything will explode when you try to launch your server.
精彩评论