开发者

Extra params in Rails 3 routes and resources

开发者 https://www.devze.com 2023-01-15 20:57 出处:网络
The new rails routes are great in many aspects, but I am looking for the best way to achieve page caching with pages and formats like I had in rails 2.x and am coming up short

The new rails routes are great in many aspects, but I am looking for the best way to achieve page caching with pages and formats like I had in rails 2.x and am coming up short

I have many possi开发者_如何学编程ble desired routes of the basic formulas:

/(bazes/<baz id>/)(foos/<foo id>/)bars/page/<page num>/<format>

Example routes:

/bars/page/1/xml
/foos/1/bars/page/2/html
/bazes/3/foos/1/bars/page/1/json
/bazes/3/bars/page/2/xml

In English:

Give me all bars, page 1, formatted xml
Give me all bars that belong to foo 1, page 2, formatted html
Give me all bars that belong to baz 3 AND foo 1, page 1, formatted json
Give me all bars that belong to baz 3, page 2, formatted xml

I used to be able to do this with a bunch of named routes:

map.baz_foo_bars '/bazes/:baz_id/foos/:foo_id/bars/page/:page/:format', :controller => 'bars', :action => 'formatted_bars'

but this seems wrong in Rails 3 and I think I am missing something that can solve my routing woes efficiently. How can i achieve these routing patterns with Rails 3 routing?


I was able to get it with a single match statement

match "(/bazess/:baz_id)(/foos/:foo_id)/bars(/page/:page)(/:format)" => "bars#index", :as => :bars
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号