将轨道应用程序封装在其他应用程序内部
我在 Rails 应用程序中构建了一个自定义管理面板,允许通过 GUI 界面编辑某些模型的内容。我最初设计了“管理”应用程序作为父应用程序(及其 MVC、Gemfile、迁移等),并创建了子应用程序(在名为 frontends 的目录中)作为管理模型的网站界面。子应用程序继承了父管理应用程序的 MVC,允许在现有管理架构上设计和构建网站前端,而无需为每个新项目不断重新开发管理网站。
我的本地计算机上的结构目前如下所示:
Administration Application <-- Individual git repo
-> app
-> admin
-> config
...
-> frontends
-> Website_1 <-- Individual git repo
-> app
-> config
...
-> Website_2 <-- Individual git repo
-> app
-> config
...
当前前端由配置中的一个简单的 frontend.yml
文件标识,该文件在管理应用程序之前在初始化程序中加载前端应用程序。
然而,我觉得拥有这样的嵌套结构是不谨慎的。首先,git repos 的嵌套在我的本地机器上很混乱,更重要的是,在相对较短的时间内切换项目的上下文极其困难。例如,如果我想从 Website_1 切换到 Website_2,我必须退出 rails server
并运行切换前端的 rake 任务。当前端使用管理应用程序的不同分支时,它也会变得更加麻烦。我发现自己在 git 和 rake 的上下文切换上浪费了很多时间,以便继续开发我的项目。
我想更改应用程序的结构,其中每个前端都是其自己独立的 Rails 应用程序。看来这将使切换开发环境变得更加简单——一次允许多个应用程序在 Rails 服务器中运行、测试等。我还希望能够继续容纳git 下的管理应用程序——因为该应用程序的一系列分支和标签有不同的风格。
进行这种重新配置的最佳方法是什么?我正在考虑创建管理应用程序的 gem 并从 Bundler 加载它。
I have built a custom administration panel into a Rails application that allows content editing of certain models through a gui interface. I initially designed the "admin" app to act as a parent applications—with its MVC, Gemfile, migrations, etc.—and created sub-applications (in a directory called frontends) that act as website interfaces to the admin's models. The sub applications inherit the MVC from the parent admin application, allowing for website frontends to be designed and build upon the existing admin architecture without continually re-developing admin sites for each new project.
The structure on my local machine currently looks like this:
Administration Application <-- Individual git repo
-> app
-> admin
-> config
...
-> frontends
-> Website_1 <-- Individual git repo
-> app
-> config
...
-> Website_2 <-- Individual git repo
-> app
-> config
...
The current frontend is identified by a simple frontend.yml
file in the config that loads the frontend application in the initializer before the admin application.
I feel like it's imprudent, however, to have a nested structured like this. First the nesting of git repos is messy on my location machine, and more importantly, it's extremely hard to switch the context of a project in a relatively short period of time. For example, if I wanted to switch from Website_1 to Website_2, I have to quit rails server
and run a rake task that switches frontends. It also becomes a little more cumbersome when a frontend uses a different branch of the administration application. I find myself spending a lot of wasted time in git and rake switching between contexts in order to continue development on my projects.
I would like to change the structure of the application where each frontend is its own independent Rails application. It seems this would make it more simple to switch development contexts—allowing more than one application at a time to be running in rails server
, testing, etc. I also want to be able to continue to house the administration application under git—since there are different flavors of the app throughout a series of branches and tags.
What would be the best way to approach this reconfiguration? I was thinking of creating a gem of the administration application and loading it from Bundler.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为宝石是你最好的选择。具体来说,我会考虑使用引擎;引擎是一个可以直接安装在routes.rb中的gem,使用如下所示:
引擎本质上是直接安装到其他应用程序中的迷你应用程序,这听起来正是您所需要的。
有关如何开始的更多信息,请查看 Rails 引擎文档。这是一个方便的您可以按照进行演练,其中包含指向 enginex 的链接,这是一个引导引擎的快速生成器宝石。
I think a gem is your best bet here. Specifically, I'd look into using an engine; an engine is a gem that's directly mountable inside your routes.rb using something like this:
Engines are essentially mini-applications that mount directly into other applications, which sounds like precisely what you need here.
For more information on how to get started, check out the Rails engine documentation. And here's a handy walkthrough you can follow that includes a link to enginex, a quick generator to bootstrap engine gems.