No commit activity in last 3 years
No release in over 3 years
This gem provides a model and simple controller for storing global application configuration in a database. This allows the configuration to change without source code modifications.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 1.3.5
>= 1.8.8
>= 0.3.14
>= 0.17.0
>= 1.3.8

Runtime

>= 3.2.16
 Project Readme

configvars_rails¶ ↑

Global configuration variables for a Ruby on Rails 3 application.

Configuration for Rails application is idiomatically stored in the source code, under the config/ directory. This approach has many upsides, such as having the configuration go under version control together with the rest of the code.

However, it also means that the source code has to be modified to make any configuration change. This makes it unlikely that the same code can be used in different deployments.

Installation¶ ↑

Scaffold the model, controller, and views.

rails g configvars:all

Note: the code inside the models and controllers is tucked away in the plug-in. The scaffold model and controller is there as an point. You will be able to update the plug-in without regenerating the scaffolds.

Edit app/controllers/config_vars_controller.rb to plug in your access control mechanism.

Usage¶ ↑

Configuration variables are defined as follows:

ConfigVars.string :variable_name, 'default value'
ConfigVars.string(:variable_name) { 'block producing default value' }

It is safe to define configuration variables anywhere in your code - make sure it gets loaded in development mode, though! The scaffold defines a couple variables in config/initializers/config_vars.rb

Variables can be redefined. Other plugins can define their own variables, as long as they include configvars_rails as a gem dependency, to ensure proper load order.

When the application is running, a rudimentary UI for editing configuration variables is available at

http://your-app-server/config_vars

By default, the page is protected with HTTP Basic authentication. The default username:password combo is config:vars. The credentials can be tweaked by (you guessed!) changing the config_vars.http_user and config_vars.http_password configuration variables.

You can get HTTP Basic authentication for your other actions by calling config_vars_auth in your controllers, as if it was before_filter. This is particularly handy as a quick patch the authorization issues that come up when open-sourcing an application that’s running in production.

config_vars_auth, :except => :index

Note on Patches/Pull Requests¶ ↑

  • Fork the project.

  • Make your feature addition or bug fix.

  • Add tests for it. This is important so I don’t break it in a future version unintentionally.

  • Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)

  • Send me a pull request. Bonus points for topic branches.

Copyright © 2010 Victor Costan, released under the MIT license