Ruby on Railsの 2系と3系のRoutingの違いを調べたのでメモ。
# Rails 2:
map.connect 'hello_world', :controller => 'posts', :action => 'index'
# Rails 3:
match 'hello_world' => 'posts#index'
# Rails 2:
map.resources :users
# Rails 3:
resources :users
# Rails 2
map.resources :games, :member => { :download => :get }, :collection => { :favourites => :get }
# Rails 3
resources :games do
get :download, :on => :member
get :favourites, :on => :collection
end
# Rails 3
resources :games do
member do
get :download
end
collection do
get :favourites
end
end
# Rails 2
map.root :controller => 'posts', :action => 'index'
# Rails 3
root :to => 'posts#index'
# Rails 2
map.namespace :admin do |admin|
admin.root :controller => 'posts'
end
# Rails 3
namespace :admin do
root :to => "admin/posts#index"
end
# Rails 2
map.connect 'posts/:year/:month', :controller => 'posts',
:month => nil, :requirements => { :year => /\\d{4}/ }
# Rails 3
match 'posts/:year(/:month)' => 'posts#index', :constraints => { :year => /\\d{4}/ }
【参考】
・Rails 3: Routing Examples - Mark Connell