For the most part, routing is unchanged in the upcoming Rails 2.2 release. But there are two changes that add a little extra syntactic sugar to your routes.

First, as Ryan Daigle covered last month, there’s a new :shallow option for nested routes. This change goes a long way to answer the classic objections to deeply-nested routes. What shallow nesting does is give you additional route helpers. For example, with this declaration:


map.resources :rooms, :shallow => true do |room|
  room.resources :shelves do |shelf|
    shelf.resources : books
  end
end

Any of these routes will be recognized:


/rooms/1/shelves/2/books/3   ==> room_shelf_book_path(1,2,3)
/shelves/2/books/3           ==> shelf_book_path(2,3)
/books/3                     ==> book_path(3)

You can also combine shallow nesting with :has_one or :has_many for a more compressed syntax:


map.resources :rooms, :has_many => { :shelves => :books }, :shallow => true

The second change is that you can now supply an array of methods for new member or collection routes on resources. With Rails 2.1, you had to either pick a method or use the wildcard :any method. With Rails 2.2, you can specify just the verbs that a route really needs:


map.resources :books, :collection => { :search => [:get, :post] }