将大型 Rails 应用程序分解为较小的应用程序? [英] Breaking a large rails app into smaller apps?

查看:23
本文介绍了将大型 Rails 应用程序分解为较小的应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含 600 个模型的 Rails 应用程序,很快就会增长到 800-1000 个.我想对 rails 应用程序进行分段,以便仅加载某些模型并因此充当单独的应用程序,但都共享相同的基本模型.这样做是否有标准做法?

I have a Rails app with 600 models and that will soon grow to 800-1000. I'd like to segment the rails app so that only certain models get loaded and therefore act as a separate app, but all share the same base models. Is there a standard practice for doing this?

我在 2.3.8

编辑 2:

问题在于,许多模型是相似的,但又足够不同,以至于需要编写一个新类,即将它们全部放在一个模型中所需的逻辑将是可怕的.一些模型可以移出到 rake 任务或 lib 目录中,但只有大约 30 个左右.有些是抽象类,充当模型树的一个分支的父类.但是,大多数都与数据库表有关.我正在考虑在部署时通过引擎将应用程序的一部分分割成插件,以便一个应用程序只能处理一组模型(它们是独立的),但为了方便起见,我可以将它们全部放在一起开发和一个 git repo.除非其他人有更好的主意,否则我将沿着这条路线走下去,我会回帖让您知道进展如何.

The problem is that many models are similar, but different just enough that it warrants writing a new class, i.e. the logic required to put it all in one model would be horrendous. Some of the models could be moved out into rake tasks or the lib directory, but only about 30 or so. Some are abstract classes that act as parents of one arm of the model tree. However, most relate to database tables. I am thinking about at deploy time segmenting parts of the app into plugins via Engines so that one app can only handle one set of models (they are independent) but so that I can keep them all together in development and in one git repo for convenience. I"m going to go down this route unless someone else has a better idea, and I'll post back to let you know how it goes.

推荐答案

老兄,模型的数量真是太疯狂了……无论如何,为了处理复杂的逻辑并轻松地在其他项目中重用它们,我会向您推荐引擎(来自2.3+ 是 Rails 的一部分).

Dude, thats a pretty insane amount of models... anyways for handling complex logic and easily reuse them across other projects I would recommend to you the engines (from 2.3+ is part of Rails).

有了它,您可以将模型拆分为不同的模块(引擎)

With that in place you can split your model in different modules (engines)

http://railscasts.com/episodes/149-rails-engines

托尼奥

这篇关于将大型 Rails 应用程序分解为较小的应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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