3

Would it be possible to have a namespace to be the root for a subdomain in rails 3?

Currently my routes are:

  namespace :mobile do
    resources :home
    resources :profiles
    root :to => "/mobile/home#index"
  end

  constraints subdomain: 'm' do
    root :to => 'mobile/home#index'
    resources :home
    resources :profile
    resources :messages
    root :to => 'mobile/home#index'
  end
Rubytastic
  • 15,001
  • 18
  • 87
  • 175

1 Answers1

8

You can but the namespace inside a subdomain constraint if that's what you're asking

constraints subdomain: 'm' do
  namespace :mobile do
    resources :home
    resources :profiles
  end
  resources :messages
  root :to => 'mobile/home#index'
end

Or there's this answer here: From Namespace to Subdomain? which advocates this approach:

constraints :subdomain => "mobile" do
  scope :module => "mobile", :as => "mobile" do
    resources :profiles
    resources :home
  end
end
Community
  • 1
  • 1
Richard Jordan
  • 8,066
  • 3
  • 39
  • 45