在子域 Rails 3.1 上安装引擎
我正在用可安装引擎做一些实验。首先,我需要您对场景的意见,我们在应用程序中将“大模块块”制作为“可安装引擎”是一个好主意吗?
我尝试过,效果很好,在可安装引擎中,我们可以全局访问应用程序的模型,在应用程序中,我们可以访问带有模块前缀的引擎模型。所以它对我来说非常有用。
现在回到原来的问题:
我想将引擎安装到子域,以便每个具有特定子域的请求都应该由该特定引擎提供服务。我用了这段代码。
root :to=>'dashboard#index'
scope :subdomain => 'admin' do
mount MyAdmin::Engine => '/'
end
在本例中,mydomain.com
和 admin.mydomain.com
转到仪表板控制器
。如果我像这样更改首选项,
scope :subdomain => 'admin' do
mount MyAdmin::Engine => '/'
end
root :to=>'dashboard#index'
在这种情况下,mydomain.com
和 admin.mydomain.com
会转到引擎特定的根控制器
。
我们如何完成这个场景并在特定的子域上安装引擎?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我通过使用这些路由条目来完成任务:
I accomplish the task by using these route entries:
使用 Rails 3.2.12 和 ruby 1.9.3-194,我找到了一个不同的解决方案,该解决方案也可以在本地工作以避免 www.允许某个子域存在引擎时出现子域问题。
我可能完全错了,但到目前为止它正在发挥作用。
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.
I could totally be wrong but it's working so far.