简体   繁体   English

在两个Rails应用程序之间共享模型

[英]sharing models between two rails app

I have two apps - A and B, which do different tasks on the same database. 我有两个应用程序-A和B,它们在同一个数据库上执行不同的任务。

It occurred to me that when I try to modify model (say x), I have to do the followings. 我想到当我尝试修改模型(例如x)时,我必须执行以下操作。

  1. modify x.rb in app A and run tests. 在应用A中修改x.rb并运行测试。

  2. replace x.rb in B with x.rb in A. 用A中的x.rb替换B中的x.rb。

  3. run tests in B and fail. 在B中运行测试并失败。

  4. find errors in B. 查找B中的错误。

  5. apply to A. 适用于A。

Apparently, it sucks. 显然,它很烂。 Is there any good practice for this case? 这个案例有什么好的做法吗?

编写一个gem并在两个应用程序中共享。

You can use an engine : http://guides.rubyonrails.org/engines.html 您可以使用引擎: http : //guides.rubyonrails.org/engines.html

Engine have shared models for your x applications, if you modify one model each application will inherit the change. 引擎为您的x应用程序提供了共享模型,如果您修改一个模型,则每个应用程序都将继承更改。

In each app, you will add the references in gemfile : 在每个应用程序中,您将在gemfile中添加引用:

gem 'my_engine', :path => 'engine_path_project'

and you can write test in the dummy application into the engine project. 您可以在虚拟应用程序中将测试写入引擎项目。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM