把 rails route file 拆成不同檔案.
之前:
# config/routes.rb
ActionController::Routing::Routes.draw do |map|
map.resources :posts
map.resources :comments
map.logout '/logout', :controller => 'sessions', :action => 'destroy'
map.login '/login', :controller => 'sessions', :action => 'create'
map.namespace :developer do |dev|
dev.resources :posts
dev.resources :comments
dev.logout '/logout', :controller => 'sessions', :action => 'destroy'
dev.login '/login', :controller => 'sessions', :action => 'create'
end
map.namespace :admin do |admin|
admin.resources :posts
admin.resources :comments
admin.logout '/logout', :controller => 'sessions', :action => 'destroy'
admin.login '/login', :controller => 'sessions', :action => 'create'
end
map.namespace :api do |api|
api.resources :posts
api.resources :comments
api.logout '/logout', :controller => 'sessions', :action => 'destroy'
api.login '/login', :controller => 'sessions', :action => 'create'
end
end
之後:
# config/routes.rb
ActionController::Routing::Routes.draw do |map|
map.resources :posts
map.resources :comments
map.logout '/logout', :controller => 'sessions', :action => 'destroy'
map.login '/login', :controller => 'sessions', :action => 'create'
end
# config/routes/developer.rb
ActionController::Routing::Routes.draw do |map|
map.namespace :developer do |dev|
dev.resources :posts
dev.resources :comments
dev.logout '/logout', :controller => 'sessions', :action => 'destroy'
dev.login '/login', :controller => 'sessions', :action => 'create'
end
end
# config/routes/admin.rb
ActionController::Routing::Routes.draw do |map|
map.namespace :admin do |admin|
admin.resources :posts
admin.resources :comments
admin.logout '/logout', :controller => 'sessions', :action => 'destroy'
admin.login '/login', :controller => 'sessions', :action => 'create'
end
end
# config/routes/api.rb
ActionController::Routing::Routes.draw do |map|
map.namespace :api do |api|
api.resources :posts
api.resources :comments
api.logout '/logout', :controller => 'sessions', :action => 'destroy'
api.login '/login', :controller => 'sessions', :action => 'create'
end
end
In Rails3, you can set the configs in config/application.rb
config.paths.config.routes.concat Dir[Rails.root.join("config/routes/*.rb")]
沒有留言:
張貼留言