在子域 Rails 3.1 上安装引擎

发布于 2025-01-05 12:40:02 字数 727 浏览 3 评论 0原文

我正在用可安装引擎做一些实验。首先,我需要您对场景的意见,我们在应用程序中将“大模块块”制作为“可安装引擎”是一个好主意吗?

我尝试过,效果很好,在可安装引擎中,我们可以全局访问应用程序的模型,在应用程序中,我们可以访问带有模块前缀的引擎模型。所以它对我来说非常有用。

现在回到原来的问题:

我想将引擎安装到子域,以便每个具有特定子域的请求都应该由该特定引擎提供服务。我用了这段代码。

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

在本例中,mydomain.comadmin.mydomain.com 转到仪表板控制器。如果我像这样更改首选项,

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

在这种情况下,mydomain.comadmin.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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

初相遇 2025-01-12 12:40:02

我通过使用这些路由条目来完成任务:

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

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
儭儭莪哋寶赑 2025-01-12 12:40:02

使用 Rails 3.2.12 和 ruby​​ 1.9.3-194,我找到了一个不同的解决方案,该解决方案也可以在本地工作以避免 www.允许某个子域存在引擎时出现子域问题。

get "home/index"

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

root :to => 'home#index'

我可能完全错了,但到目前为止它正在发挥作用。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文