Best way to manage Rails application configuration

2019-05-03 08:18发布

问题:

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?

Thanks in advance.

回答1:

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.



回答2:

https://github.com/Squeegy/rails-settings



回答3:

Not really DB-based, but check this Gem on GitHub for managing settings in YML files:

https://github.com/modcloth/mc-settings