Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

make subdomain have a namespace as root?

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
like image 852
Rubytastic Avatar asked Dec 30 '25 13:12

Rubytastic


1 Answers

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
like image 54
Richard Jordan Avatar answered Jan 02 '26 03:01

Richard Jordan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!