Skip to content


Subversion checkout URL

You can clone with
Download ZIP
database-driven settings with a trim interface and a controller for management.
Branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.


Settings Generator

On most of my projects at work (APIs and their accompanying CMS apps) we have need of settings that can be stored in the database, and updated by our staff. Perhaps the version of our app on the Beta server needs to communicate with a 3rd party's test platform, while the version on the Prod server needs to work with the 3rd party's production platform. Or maybe you just want Bill in Accounting to specify the background color for his spiffy CMS.


We can install this generator in a few easy steps:

1) Create our rails project:

rails spiffycms
cd spiffycms

2) Run the generator:

ruby script/generate settings

3) Update our database:

rake db:migrate

4) Test our new installation:

rake db:test:prepare
rake test


So how do we use it? After installation, there are three ways to use our new settings:

# Get/Set settings explicitly #
Setting.set('admin', '')
Setting.get('admin')    # returns ''

# Get/Set implicitly, which is more fun #
Setting.admin = ''
Setting.admin    # returns ''

The third way is to launch the app, and go to /settings where you'll be treated to a GUI with your basic CRUD functionality. Pretty slick. Be sure, if you have any authentication in your app, to include it in settings_controller.rb, or anyone out there will be able to change your site's settings. That's no fun.

Something went wrong with that request. Please try again.