Skip to content

Instantly share code, notes, and snippets.

@mattsoutherden
Created December 14, 2011 12:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattsoutherden/1476415 to your computer and use it in GitHub Desktop.
Save mattsoutherden/1476415 to your computer and use it in GitHub Desktop.
Rails 3 Routing
# Rails 2 routing
#
map.resource :city, :as => ":city" do |city|
city.login 'login', :controller => 'cities', :action => 'login'
city.resources :orders, :only => [ :show, :update ]
end
# city_login /:city/login {:controller=>"cities", :action=>"login"}
#
# city_order GET /:city/orders/:id(.:format) {:controller=>"orders", :action=>"show"}
# PUT /:city/orders/:id(.:format) {:controller=>"orders", :action=>"update"}
# Rails 3 Routes
#
resource :cities, :as => 'city', :path => ":city" do
match 'login' => 'cities#login'
resources :orders, :only => [ :show, :update ]
end
# login_city /:city/login(.:format) {:action=>"login", :controller=>"cities"}
#
# city_order GET /:city/orders/:id(.:format) {:action=>"show", :controller=>"orders"}
# PUT /:city/orders/:id(.:format) {:action=>"update", :controller=>"orders"}
Note that in Rails 2 the login route helper is city_login_path(), whereas Rails 3 the
generated helper is login_city_path(). But the nested order routes are both city_order_path()
Is there a way to make the single 'match' route consistent with the resources in Rails 3?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment