使用 Ruby on Rails 的多个应用程序 [英] Multiple applications with Ruby on Rails

查看:45
本文介绍了使用 Ruby on Rails 的多个应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以让一个 Ruby on Rails 安装有多个应用程序,这些应用程序共享一个通用模型?

Is it possible to have a single Ruby on Rails installations have multiple applications, that share a common model?

例如,我想要一个前端应用程序和后端管理控制台,但两者共享相同的模型.

For example, I want to have a frontend application, as well as backend administration console, but both share the same model.

这类似于 Symfony 在 PHP 中的工作方式.

This is similar to the way Symfony works in PHP.

提前致谢!

推荐答案

拥有管理面板的最简单方法是使用命名空间.您只需将所有管理内容放入 admin 命名空间.这是非常普遍的做法.

The easiest way to have admin panel is to use namespaces. You just put all admin stuff to admin namespace. It is very common practice.

另一方面,如果您想让两个(或更多)应用程序共享相同的数据库和模型,这很容易.我有一个项目有两个 RoR 应用程序共享同一个数据库.所以这是我的想法:

On the other hand, if you want to have two (or more) applications sharing the same database and models it is quite easy. I have one project that has two RoR applications sharing the same database. So here are my thoughts about it:

  1. 我将所有迁移都放在我的第一个项目中.如果您将所有这些(或少数几个)都放在两个应用程序中,可能会很混乱.然后,迁移后,您可以将 schema.db 复制到第二个项目,或者只是我们一个符号链接(在类 Unix 系统中),不再关心它.
  2. 如果您想在两个应用程序中共享某个模型,那么您可以复制模型文件或使用符号链接.我使用了第一种方法,因为我不想复制我不在第二个应用程序中使用的所有相关模型.
  3. 效果很好.但在这种情况下,您还必须为两个应用程序设置服务器.我为这两个应用程序使用了不同的子域.

希望有帮助!

这篇关于使用 Ruby on Rails 的多个应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆