Rails.application.routes.draw do resources :blogs resources :posts namespace :admin do resources :blogs do resources :posts end end scope :constraints => lambda{ |r| Blog.where(:slug => r.path.split('/')[1]).first } do get ':blog_slug', :to => 'blogs#show' get ':blog_slug/archive', :to => 'blogs#archive' get ':blog_slug/search', :to => 'blogs#search', :as => :search_blog get ':blog_slug/feed', :to => 'blogs#feed', :format => [:rss] get ':blog_slug/:post_slug', :to => 'posts#show' end end