# What's the best way to manage settings in a Rails app?

**URL:** <https://www.ruby-forum.com/t/whats-the-best-way-to-manage-settings-in-a-rails-app/47832>\
**Category:** Rails\
**Created:** [November 14, 2005, 7:53am UTC](https://www.ruby-forum.com/t/whats-the-best-way-to-manage-settings-in-a-rails-app/47832 "2005-11-14T07:53:34Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![pergesu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/22d042/32.png) [@pergesu](https://www.ruby-forum.com/u/pergesu)\
**Post date:** [November 14, 2005, 7:53am UTC](https://www.ruby-forum.com/t/whats-the-best-way-to-manage-settings-in-a-rails-app/47832/1 "2005-11-14T07:53:34Z")

</div>

How should we manage settings in an app? Typo, for example, has a  
settings table with stuff like title, subtitle, enable comments, etc.  
It’s basically a name for the setting and the value. Is this the best  
approach for settings that should be configured for the app? The  
majority of the time they won’t change (title), but you’d use caching  
in some place so you don’t take a performance hit. Anyway I’ve just  
been wondering the best way to allow users of an app to manage  
particular settings.

Thanks,  
Pat

---

<div class="post-metadata">

**Author:** ![pergesu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/22d042/32.png) [@pergesu](https://www.ruby-forum.com/u/pergesu)\
**Post date:** [November 14, 2005, 8:20am UTC](https://www.ruby-forum.com/t/whats-the-best-way-to-manage-settings-in-a-rails-app/47832/2 "2005-11-14T08:20:38Z")

</div>

[http://wiki.rubyonrails.com/rails/pages/HowtoAddYourOwnConfigInfo](http://wiki.rubyonrails.com/rails/pages/HowtoAddYourOwnConfigInfo)  
gives a good description of different options.

I’d like to have a nice interface to modify settings, because the end  
users won’t have access to the text files to modify settings  
themselves. Seems like using a db is the best approach? I just found  
out on IRC that if I use a YAML file I can easily save it by calling  
save on the YAML object, and it will automatically rewrite the file.  
Why does Typo use a db though, and what’s the best approach for me?

Thanks,  
Pat

---

<div class="post-metadata">

**Author:** ![pergesu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/22d042/32.png) [@pergesu](https://www.ruby-forum.com/u/pergesu)\
**Post date:** [November 26, 2005, 12:24pm UTC](https://www.ruby-forum.com/t/whats-the-best-way-to-manage-settings-in-a-rails-app/47832/3 "2005-11-26T12:24:32Z")

</div>

Hi,

I have to pick this up:

2005/11/14, Pat M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> I’d like to have a nice interface to modify settings, because the end  
> users won’t have access to the text files to modify settings  
> themselves. Seems like using a db is the best approach? I just found  
> out on IRC that if I use a YAML file I can easily save it by calling  
> save on the YAML object, and it will automatically rewrite the file.  
> Why does Typo use a db though, and what’s the best approach for me?

This is also the question I wonder. Did someone already solve this in  
rails?

TIA,  
Beate

---

<div class="post-metadata">

**Author:** ![pergesu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/22d042/32.png) [@pergesu](https://www.ruby-forum.com/u/pergesu)\
**Post date:** [November 26, 2005, 4:26pm UTC](https://www.ruby-forum.com/t/whats-the-best-way-to-manage-settings-in-a-rails-app/47832/4 "2005-11-26T16:26:06Z")

</div>

Hi !

2005/11/14, Pat M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> How should we manage settings in an app? Typo, for example, has a  
> settings table with stuff like title, subtitle, enable comments, etc.  
> It’s basically a name for the setting and the value. Is this the best  
> approach for settings that should be configured for the app? The  
> majority of the time they won’t change (title), but you’d use caching  
> in some place so you don’t take a performance hit. Anyway I’ve just  
> been wondering the best way to allow users of an app to manage  
> particular settings.

You’ll have to decide for yourself what is the best approach. I have  
tried the two following ways:

CREATE TABLE settings (  
id  
name  
group\_name  
description  
type  
str\_value  
int\_value  
product\_id  
product\_category\_id  
);

and

CREATE TABLE settings (  
id  
paypal\_business  
paypal\_ipn\_url  
);

In the first case, I have a table record per setting. Each record can  
be edited on a special screen I made in the application. It is  
basically the scaffolded list, but I replaced the value columns with a  
conditional partial rendering. Then, I show an HTML control depending  
on the type of configuration setting.

In the second case, the application is just starting. I’ll have a  
single screen where all configuration will be done. It is not done at  
the moment, but I will be mostly be able to regenerate it using the  
scaffolded edit screen.

In both cases I was after a single thing: ease of backup. Backing up  
the DB, I have EVERYTHING - no other files need to be backed up at the  
same time.

As I said at start, you’ll need to decide for yourself which method is  
best for you, your team, your application and your users, in reverse  
order 🙂

Have a nice day !
