Reputation: 4848
I've just started working out of a rails 3 project in github and the routes.rb file doesn't seem to follow the usual format (eg: map.connect 'blahblahblah'). Instead it looks something like so:
MyProject::Application.routes.draw do
root :to => 'content#index'
match '/logout' => 'sessions#destroy', :as => :logout
match '/login' => 'sessions#new', :as => :login
resources :accounts do
resources :users
member do
post :upgrade
get :cancel
end
end
namespace :dashboard do
resource :control_panel do
member do
post :show_info
end
end
end
There a little more info after that but I've excluded it for brevitys sake. Can someone tell me how this file structure operates and specifically the difference between 'resource' and 'namespace' above?
Thanks, gearoid.
Upvotes: 1
Views: 96
Reputation: 1214
Routing in Rails 3 got a pretty major overhaul. Seems like you should probably read up on the new world order. Check out the Rails 3 Routing Guide. It has a section on Resources and one on Namespaces.
Upvotes: 0
Reputation: 84140
This is the rails 3 syntax for routing. map.connect was the rails 2 syntax.
Documentation for rails 3 routing.
Resource creates routes for the 7 CRUD actions in rails (Create, Index, Show, Update, Edit, New and Destroy.) Namespace allows you to namespace the routes.
namespace :dashboard do
resource :control_panel do
member do
post :show_info
end
end
end
This creates the 7 CRUD routes for control_panel under the dashboard namespace, such as:
http://localhost:3000/dashboard/control_panel/new
http://localhost:3000/dashboard/control_panel/show/1
Upvotes: 3