rails3 change default resources route name

原创文章,转载请注明来源并保留原文链接

rails3的路由足够强大,可以基本上配出你想要的任意url。
现在有这样一个需求:
resources :posts 改为 resources :pages(controller 还是走posts)。
如何实现?
非常简单

resources :page, :controller => :posts
# 看看生成的路由
page_index GET    /page(.:format)      {:controller=>"posts", :action=>"index"}
page_index POST   /page(.:format)     {:controller=>"posts", :action=>"create"}
new_page GET    /page/new(.:format)  {:controller=>"posts", :action=>"new"}
edit_page GET    /page/:id/edit(.:format) {:controller=>"posts", :action=>"edit"}
page GET    /page/:id(.:format)   {:controller=>"posts", :action=>"show"}
page PUT    /page/:id(.:format)   {:controller=>"posts", :action=>"update"}
page DELETE /page/:id(.:format) {:controller=>"posts", :action=>"destroy"}

OK!

Leave a Reply

Your email address will not be published. Required fields are marked *