跨 Rails 应用程序共享数据和模型的最常见做法
我想在两个独立的 Rails 应用程序之间共享数据。
每个应用程序都有一个产品的概念。这两个应用程序共享公共字段(例如 id、名称),但每个应用程序也有另一个应用程序不需要的字段(例如 some_application_specific_flag)。
就 1) 共享 Rails 模型和 2) 数据库结构而言,最常见的架构实践是什么?
模型:完全独立的模型?每个应用程序的公共基础模型和子类?还有别的事吗?
数据库结构:用于共享数据的通用表,以及用于特定于应用程序的数据的特定于应用程序的表?
I want to share data across two separate Rails applications.
Each application has the concept of a product. The two applications share common fields (eg. id, name) but each application also has fields that the other application does not need (eg. some_application_specific_flag).
What is the most common architectural practice as far as 1) sharing Rails models and 2) database structure?
Models: Completely separate models? Common base models and subclasses for each application? Something else?
Database structure: A common table for shared data and then application-specific tables for application-specific data?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Ruby gem 通常是一个很好的解决方案,您可以将常见模型包含到其中。在我们公司,我们使用 ruby gem 来包含多个在线商店的通用逻辑。对于另一组项目,Ruby gem 包含所有与样式相关的内容,以使多个单独的网站看起来像一个网站。
是否使用单独的模型或子类取决于您和您的应用程序。这取决于。我会尝试使用单独的模型,除非有充分的理由不这样做。
如果您只是共享数据,则可以是 ruby gem(如果您的数据很少)或数据库。在数据库中,我会使用公用表或公用数据库,具体取决于数据的数量和复杂性。在大多数情况下,我可能会选择通用数据库(而不是表)。
Ruby gem is often a good solution, you can include common models into it. In our company we use a ruby gem to contain common logic for several online shops. For another set of projects, a ruby gem contains all style-related stuff to make several separate websites looks like one.
Whether to use separate models or subclasses is up to you and your application. It depends. I would try to use separate models unless there's a good reason not to.
If you're just sharing data, that can be either a ruby gem (if you have very little data) or a database. In a database, I would use either a common table or a common database, depending on the volume and complexity of the data. I'd probably go for a common database (as opposed to a table) in most cases.