What is the Rails router's namespace and scope?

Answer

namespace groups routes under a URL prefix AND a module prefix. namespace :admin do resources :posts end generates /admin/posts mapped to Admin::PostsController with named routes like admin_posts_path. scope is more flexible — it can add a URL prefix without a module: scope '/admin' do resources :posts end maps to PostsController (no module). scope module: :admin adds module but no URL prefix. Use namespace for fully separated admin sections; use scope when you want URL prefixing without module nesting or vice versa.