在不同的Rails应用程序之间共享ActiveRecord模型和数据的最佳方式?

时间:2023-01-24 13:05:32

I have several rails applications that will use the same core set of Models and data, for example:

我有几个rails应用程序将使用相同的核心模型和数据集,例如:

  • Apps
  • 应用
  • Developers
  • 开发商
  • Categories
  • 分类

Each app builds on top of this core data and uses it in different ways. For example, I might have something like this in another app:

每个应用程序都建立在这个核心数据之上,并以不同的方式使用它。例如,我可能在另一个应用程序中有这样的东西:

  • Activity
  • 活动
  • Users
  • 用户
  • Apps (shared)
  • 应用(共享)
  • Developers (shared)
  • 开发人员(共享)
  • Categories (shared)
  • 分类(共享)

What is the best way to share the Models and data between them? The Apps, Developers and Category data will all be the same for every app so I would rather not have to duplicate the data in every app's database.

在它们之间共享模型和数据的最佳方式是什么?应用程序,开发人员和类别数据对于每个应用程序都是相同的,因此我不想在每个应用程序的数据库中复制数据。

EDIT: I'm thinking through a couple of possible solutions:

编辑:我正在考虑几个可能的解决方案:

  • Rails engines (would solve the duplicate Models in different apps problem, but not the shared data issue)
  • Rails引擎(可以解决不同应用程序中的重复模型问题,但不会解决共享数据问题)
  • Using ActiveResource to access the core data (solves the shared data, but not the shared model issue)
  • 使用ActiveResource访问核心数据(解决共享数据,但不解决共享模型问题)

1 个解决方案

#1


4  

I'm using a shared database to solve the shared data problem between heroku and a server on EC2 which does some background processing I can't do on heroku. In my case I'm using the same application, but really all I'm doing is using delayed_job on the EC2, so I'm only using the models from the app there. If I were going to use them in another application, I would probably go through the trouble of creating a gem to use between them.

我正在使用共享数据库来解决heroku和EC2上的服务器之间的共享数据问题,该问题执行了一些我无法在heroku上执行的后台处理。在我的情况下,我使用相同的应用程序,但实际上我正在做的就是在EC2上使用delayed_job,所以我只使用应用程序中的模型。如果我打算在另一个应用程序中使用它们,我可能会遇到创建在它们之间使用的gem的麻烦。

#1


4  

I'm using a shared database to solve the shared data problem between heroku and a server on EC2 which does some background processing I can't do on heroku. In my case I'm using the same application, but really all I'm doing is using delayed_job on the EC2, so I'm only using the models from the app there. If I were going to use them in another application, I would probably go through the trouble of creating a gem to use between them.

我正在使用共享数据库来解决heroku和EC2上的服务器之间的共享数据问题,该问题执行了一些我无法在heroku上执行的后台处理。在我的情况下,我使用相同的应用程序,但实际上我正在做的就是在EC2上使用delayed_job,所以我只使用应用程序中的模型。如果我打算在另一个应用程序中使用它们,我可能会遇到创建在它们之间使用的gem的麻烦。