Rails - 具有自定义框架的多租户应用程序 [英] Rails - Multi tenant application with customization framework

查看:20
本文介绍了Rails - 具有自定义框架的多租户应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在组织一个具有单个代码库/应用程序的多租户应用程序,使用子域来检测租户,然后在 postgres 上运行一个 SET SCHEMA 来做一些有趣的事情.

I am organizing a multi tenant application with a single code base/application using subdomains to detect the tenant, then runs a SET SCHEMA on postgres to do the fun stuff.

我的问题是某些客户需要对主代码库进行不同级别的自定义.不是很多,但肯定足以让我不想通过添加一堆 if 语句来开始破解主要模型和控制器.

My issue is that certain clients will require various levels of customization to the main codebase. Not a ton, but certainly enough to the point that I wouldn't want to start hacking the main models and controllers by adding a bunch of if statements.

使用视图加载路径覆盖视图很容易...但我的问题是:我如何提供一个好的框架来覆盖或添加基本控制器、模型和助手的功能,以便根据需要为每个租户进行调整?理想情况下,它应该非常无缝并且不会侵入主代码,并且应该提供一个合适的机制来组织自定义代码.

Overriding views is easy enough with views load paths... but my question is: How can I provide a good framework for overriding or adding functionality to the base controllers, models and helpers to tweak things for each tenant as needed? Ideally it should be pretty seamless and not invasive to the main code, and should provide a decent mechanism for organizing the customized code.

我研究了一些选项,包括使用包含/扩展(mixin).问题是在生产中,方法留在对象中(可以理解).我试过 hte mixology gem 来解决这个问题,但它并没有完全按照我的预期工作,而且它比我希望的更具侵入性,我也不清楚如何将它与模型相关联(在控制器中,我刚刚尝试通过过滤器之前/之后进行混合/取消混合).

I've investigated a few options, including using includes/extends (mixins). The issue is that in production, methods stay in the objects (understandable). I've tried hte mixology gem to work around this, but it doesn't totally work as I had intended and its a bit more invasive than I'd like it to be, I'm also unclear how to relate it to models (in the controllers I just tried mixin/unmix via before/after filters).

如果有人对如何最好地处理/解决此问题有任何想法,我将不胜感激您的反馈.FWIW 这是 Rails3

If anybody has any ideas on how to best approach/solve this issue, I would greatly appreciate your feedback. FWIW this is Rails3

推荐答案

hook + plugins 设置能满足您的需求吗?即:将附加功能构建到另一个模型中,无论您需要修改什么操作,请检查 hooks 表以查看用户是否需要任何额外的操作,hooks 表还指定要执行的操作,因此您可以轻松地为不同的用户设置不同的配置.

Would a hooks + plugins setup meet your needs? ie: build the additional functionality into another model, on whatever actions you need to modify check a hooks table to see if the user requires any extra actions, hooks table also specifies the action to take so you could easily setup different configurations for different users.

如果您找到了更好的答案,请更新.

If you found a better answer to this please update.

这篇关于Rails - 具有自定义框架的多租户应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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