8

I am doing some experiments with Mountable Engines. First i need your opinion for a scenario, Is it a good idea that we make "chunk of large modules" in an application as "mountable engines".

I tried this it works great, In mountable engine we can access models of app globally and in app we can access engine models with module prefix. So it works great for me.

Now came to original question:

I want to mount an engine to a subdomain, so that every request with specific subdomain should be served by that specific engine. I used this code.

root :to=>'dashboard#index'
scope :subdomain => 'admin' do
    mount MyAdmin::Engine => '/'
end

In this case mydomain.com and admin.mydomain.com goes to dashboard controller. If i change the preferences like that

scope :subdomain => 'admin' do
    mount MyAdmin::Engine => '/'
end
root :to=>'dashboard#index'

In this case mydomain.com and admin.mydomain.com goes to engine specific root controller.

How can we accomplish this scenario and mount an engine on specific sub-domain?

Nazar Hussain
  • 5,102
  • 6
  • 40
  • 67

2 Answers2

13

I accomplish the task by using these route entries:

scope :subdomain => 'www' do
   root :to=>'dashboard#index'
end
scope :subdomain => 'admin' do
    mount MyAdmin::Engine => '/'
end
Nazar Hussain
  • 5,102
  • 6
  • 40
  • 67
4

Working with Rails 3.2.12 and ruby 1.9.3-194 I came to a different solution that also works locally for avoiding the www. subdomain issue while allowing there to be an Engine at a certain subdomain.

get "home/index"

constraints :subdomain => 'store' do
    mount Spree::Core::Engine, :at => '/'
end

root :to => 'home#index'

I could totally be wrong but it's working so far.

samuelkobe
  • 546
  • 4
  • 16
  • Very useful! The mount directive can be made even shorter by using `mount Spree::Core::Engine => '/'` – Epigene Apr 01 '15 at 07:38