Skip to content
Oshuma edited this page Nov 13, 2010 · 8 revisions

For example, if your collection looks like this:

  $ mongo
  MongoDB shell version: 1.6.4
  connecting to: test
  > use app_config
  switched to db app_config
  > db.app_config.find()
  { "_id" : ObjectId("4cddc317da98dd42f8000001"), "admin_email" : "[email protected]" }

Setup AppConfig like so:

  AppConfig.setup do |config|
    config[:storage_method] = :mongo

    # These are the defaults:
    config[:host] = 'localhost'
    config[:port] = '27017'
    config[:database] = 'app_config'
    config[:collection] = 'app_config'

    # To authenticate, set the user and password:
    config[:user] = 'db_user'
    config[:password] = 'db_password'
  end

Then use the stored values:

  AppConfig[:admin_email]  # => '[email protected]'

  # Keys can be created (or updated) and are automatically saved back to the database:
  AppConfig[:api_key] = 'APP_API_KEY'
  AppConfig[:admin_email] = '[email protected]'
Clone this wiki locally