为构建一个“大”的Rails应用程序的最佳实践 [英] Best practice for structuring a 'large' Rails app

查看:126
本文介绍了为构建一个“大”的Rails应用程序的最佳实践的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在这里我的问题是寻求最佳实践,一般建议和见解,而不是解决一个具体的问题。

My question here is seeking best practice, general advice and insight, rather than a solution to a specific problem.

我在规划出一个Rails项目,我认为相当大的早期阶段。在最简单的层面它提供了一个千篇一律的CMS给目标用户。因此,用户注册并选择一个子域,并都获得了pretty基本的网站,CMS。

I am in the early stages of planning out a Rails project which I consider fairly large. At its simplest level it offers a cookie-cutter CMS to the target users. So users sign up and choose a subdomain and are given a pretty basic website with CMS.

因此​​,整个应用程序大约有4种不同的面到它:

Therefore the entire app has about 4 different 'sides' to it:


  • 一个销售网站销售的产品为最终用户 - www.myapp.com

  • 中央管理区,工作人员可以登录和管理帐户等 - www.myapp.com/superadmin

  • 用户自己的网站 - subdomain.myapp.com

  • 的用户管理区/ CMS - subdomain.myapp.com/admin

所以,真的是我要找的是构建应用程序的最佳实践。即,应该将其所有集于一身巨大的应用还是应在2(或更多)小应用程序被分割

So really what I'm looking for is best practice for structuring the app. i.e. should it all be rolled into one huge application or should it be split over 2 (or more) smaller apps?

如果部署为一个应用程序,我可以看到周围的布线为一体的销售网站和用户的网站,将需要一个根路径集这两个问题,再加上我不希望我的销售网站设置是通过用户访问路线网站。可以将任何东西无论是在Rails或者Apache的水平进行(mod-rewrite?),以确保没有路线查询股价?

If deployed as one application, I can see issues surrounding routing as both the sales website and the users' websites will need a root path set, plus I would not want the routes I set for the sales website being accessible through the users' websites. Can anything be done either within Rails or at Apache level (mod rewrites ?) to ensure no mixup of routes?

如果拆分成2个或更多的应用程序,你如何让应用程序共享同一个数据库?是,即使是一个好主意?是否有从(在应用程序中的一个区域像隔离问题,而不是把一切都向下)的拆分应用程序的任何好处?

If split over 2 or more applications, how do you get the applications sharing the same database? Is that even a good idea? Are there any benefits from splitting the application (like isolating problems in one area of the app, rather than bringing everything down)?

我知道这个帖子引起了很多不同的问题,但美联社preciate任何意见和见解,你可以给我。

I realise this post raises quite a few different questions, but appreciate any advice and insight you can give me.

推荐答案

我相信你的隔离问题纳入单独的应用程序的收益大于成本。我可能会只用2应用程序(一个主站点和超级管理员,一个用于客户端的网站和管理员)开始,访问同一个数据库,但是你可以做4。

I believe the benefits of isolating your concerns into separate apps outweigh the costs. I would probably start off with just 2 apps (one for the main site and superadmin, one for the client sites and admins), accessing the same database, but you could do 4.

缺点是你真的没有隔离,因为所有的应用程序都依赖于一个数据库。你最终还是会遇到扩展问题与您的数据库,但出发简单用一个数据库将让你启动。供以后扩展的一个策略是添加从数据库客户端和网站主站点应用程序使用,而管理应用程序使用主分贝。这与缓存的TON一起将让你pretty远。

The downside is you don't really have isolation since all your apps are tied to one database. You will eventually run into scaling problems with your database, but starting off simple with one database will get you launched. One strategy for scaling later would be to add a slave db that the client site and main site apps use, while the admin apps use the master db. This along with a TON of caching will get you pretty far.

有什么错有多个Rails应用门禁一体分贝,但你需要一种方法来在您的应用有着共同的code。将模型的大部分。我一直在说我作为一个git的子模块或在SVN外部共享插件折腾我的所有车型做过。具有单独的应用程序将让每个应用更小,更易于维护。

There is nothing wrong with having multiple rails apps access one db, however you will need a way to share common code across your apps. Your models for the most part. I've done this before by tossing all my models in a plugin that I share as a sub-module in git or as an external in svn. Having separate apps will make each app smaller and easier to maintain.

然而,如果你保持你的迁移?你在哪里测试你的模型?我会选择为超级管理员应用程序。此外,您进行了更改模型或模式,现在你必须检查2-4的应用程序,并确保他们仍然可以工作!

However, where do you keep your migrations? Where do you test your models? I would opt for the superadmin app. Also, you make a change to a model or the schema, and now you have to check 2-4 apps and make sure they still work!

更好的隔离,独立DB的,可通过Web的API(SOA),你不必担心应用间通信。 SOA,我认为是某一个点之后的路要走,但是SOA可能是premature当你第一次开始了。

Better isolation, separate db's and inter-app communication through web APIs (SOA) and you don't have to worry about that. SOA I think is the way to go after a certain point, but SOA might be premature when you first start out.

在任何情况下,有独立的应用程序设置你的SOA,但你不必会越过一个单一的数据库来启动。

At any rate, having separate apps sets you up for SOA but you don't have to jump beyond a single db to start.

这篇关于为构建一个“大”的Rails应用程序的最佳实践的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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