Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mount an engine on subdomain Rails 3.1

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?

like image 589
Nazar Hussain Avatar asked Feb 15 '12 12:02

Nazar Hussain


2 Answers

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
like image 198
Nazar Hussain Avatar answered Sep 28 '22 12:09

Nazar Hussain


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.

like image 40
samuelkobe Avatar answered Sep 28 '22 11:09

samuelkobe