5

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.

Chris Hart
  • 2,153
  • 1
  • 23
  • 45
  • In my search for singleton references for Ruby/Rails, I've come across many articles (including some on SO) that highlight the problems with the Singleton pattern. I'm not married to that implementation - my primary concern is that I can update the configuration in a single place and have it take effect on all instances of the application. I'd prefer to not have the moving parts involved with scripting file changes across multiple servers, so a database was my natural choice. Any solution that saves me from having to update the configuration everywhere the app runs is fine by me. – Chris Hart Aug 03 '10 at 02:43
  • This has been answered here: https://stackoverflow.com/a/2635895 – pasqal Mar 02 '23 at 09:34

3 Answers3

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.

rainkinz
  • 10,082
  • 5
  • 45
  • 73
  • Thanks for the suggestion. Do you use the ApplicationHelper module to query/deserialize/provide getter-type methods to the configuration hash? Or is there a better approach? – Chris Hart Aug 04 '10 at 02:24
1

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

Giovanni Cappellotto
  • 4,597
  • 1
  • 30
  • 33
0

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

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