管理Rails应用程序配置设置的最佳方式是否保留在数据库中? [英] Best way to manage Rails application configuration settings persisted in a database?

查看:145
本文介绍了管理Rails应用程序配置设置的最佳方式是否保留在数据库中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望有人能建议使用数据库配置Rails应用程序的最佳实践(即将配置设置保存到数据库而不是平面文件)。我的推理是,我有一个应用程序,将运行在多个服务器,有一些配置设置是相当动态,我想改变它们,而不必在每个服务器上进行更改。

I was hoping someone could suggest some best practices for configuring Rails applications using a database (i.e. persisting configuration settings to a database rather than a flat file). My reasoning for this is that I have an application that will run on multiple servers and there are some configuration settings that are fairly dynamic and I would want to change them without having to make a change on every server.

在其他语言中,我已经看到这一点,使用一个简单的配置表(如名称/值对)和一个单例,暴露配置数据并定期刷新。

In other languages, I've seen this done by using a simple configuration table (like name/value pairs) and a singleton that exposes the configuration data and periodically gets refreshed. Is there a similar - or better - way to do this with Rails?

提前感谢。

推荐答案

不是最漂亮的解决方案,我敢肯定,但我们为内部应用程序做了一件事是创建一个配置字段,它只是一个包含序列化哈希的文本字段。然后我们从db进行反序列化。

Not the prettiest solution I'm sure, but one thing we've done for our internal apps is create a 'config' field that is simply a text field containing a serialized hash. Then we deserialize on load from the db.

这篇关于管理Rails应用程序配置设置的最佳方式是否保留在数据库中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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