Routing in Rails 3 Engines
If you’re creating a new Engine in Rails 3 (or upgrading one from Rails 2), you’re probably wondering how to do the routing. This is how:
Rails.application.routes.draw do
namespace :admin do
resources :users
resource :session
match 'login' => 'admin/sessions#new', :as => 'login'
match 'logout' => 'admin/sessions#destroy', :as => 'logout'
root :to => 'admin/home#index'
end
end
Note that in Rails 3, non-resource routes (like root, login and logout above) don’t obey the namespace context when selecting the controller. This requires you to match specifically to admin/sessions rather than simply sessions.