如何重用 Rails 应用程序
我为学校校友网站开发了一个 Rails 应用程序。 现在另一所学校希望我为他们开发一个类似的网站。
我想重复使用该应用程序。数据结构将相同,但实际数据将不同。设计布局将相似,但设计本身将有所不同。
一种选择是我只是复制应用程序并对其进行修改。但在这种情况下,我需要管理 2 个应用程序的发展。
另一种选择是使应用程序通用化和可定制(尽管数据库将被分离)。视图会有很多很多分支。
我可以在多个应用程序的数据库上使用,但我确信它需要很多工作。
另一种选择是将控制器和模型移至插件,以便 2 个应用程序共享它们。
您有这样的案例经验吗?如果有的话,你能和我分享一下吗?
谢谢。
山姆
I developed a rails app for a school alumni site.
Now another school wants me to develop a similar site for them.
I want to reuse the app. Data structure will be same but the actual data will be different. Design layout will be similar but design itself will be different.
One option is that I just copy the app and modify it. But in this case, I need to manage 2 apps as they evolve.
Another option will be to make the app generalized and customizable (Database will be separated though). Views will have a lot of a lot of branches.
I could use on database for multiple apps but I am sure it will require a lot of jobs.
Another option will be to move controllers and models to plugins so that 2 apps share them.
Do you have any experience with such a case? If so, can you share it with me?
Thanks.
Sam
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
这可能有点不正统,但如果您使用 git,您可以创建两个分支,
根代码将保留在主分支中。然后,您的开发流程将是:
您可以根据需要继续在本地修改分支,但您需要小心在主/分支之间引入冲突的编辑。
This might be a little unorthodox, but if you're using git, you can create two branches
The root code will stay in the master branch. Your development flow would then be:
You can continue to locally modify the branches as needed, but you will need to be careful about introducing conflicting edits between master/branch.
如果有任何方法可以避免将代码分叉到两个单独的应用程序中的复杂性,那么您应该这样做。
按照您的建议使应用程序通用化和可定制,从而使您的一次性咨询项目更接近于独立产品(这可能更有利可图)。
If there is any way to avoid the complexity of forking your code into two separate applications you should do it.
Making the application generalized and customizable as you are suggesting moves your one off consulting project into something closer to a standalone product (which might be more profitable).
您会惊讶地发现,通过不同的样式表、布局和本地化的明智使用,您能取得多大的成果。
You'd be surprised how far you can get with different stylesheets, layouts and judicious use of localisation.
2 个应用程序将共享:
模型
帮手
控制器
他们不会共享:
视图
我还不确定数据库。
我可以使用皮肤概念来分离视图,例如:
app/views/app1/...
app/views/app2/...
我仍在考虑数据库。
2 apps will share:
Models
Helpers
Controllers
They won't share:
Views
I am not sure about database yet.
I may separate views using skin concept like:
app/views/app1/...
app/views/app2/...
I am still thinking about database.
我正在使用 git 子模块和符号链接。
Rails.root/shared
中有一个共享项目的子模块。然后是从app/models
到shared/app/models
的符号链接,等等。I'm using git submodules and symlinks. There's a submodule to the shared project in
Rails.root/shared
. Then there's symlinks fromapp/models
toshared/app/models
, and so on.