github
Advanced Search
  • Home
  • Pricing and Signup
  • Explore GitHub
  • Blog
  • Login

Squeegy / rails-settings

  • Admin
  • Watch Unwatch
  • Fork
  • Your Fork
  • Pull Request
  • Download Source
    • 110
    • 8
  • Source
  • Commits
  • Network (8)
  • Issues (0)
  • Downloads (0)
  • Wiki (1)
  • Graphs
  • Branch: master

click here to add a description

click here to add a homepage

  • Branches (1)
    • master ✓
  • Tags (0)
Sending Request…
Enable Donations

Pledgie Donations

Once activated, we'll place the following badge in your repository's detail box:
Pledgie_example
This service is courtesy of Pledgie.

Settings is a plugin that makes managing a table of global key, value pairs easy. Think of it like a global Hash stored in your database, that uses simple ActiveRecord like methods for manipulation. Keep track of any global setting that you don't want to hard code into your rails app. You can store any kind of object. Strings, numbers, arrays, or any serializable object. — Read more

  cancel

  cancel
  • Private
  • Read-Only
  • HTTP Read-Only

This URL has Read+Write access

. 
Squeegy (author)
Thu Dec 24 16:20:16 -0800 2009
commit  052beb728ca2ae59636f4efcbce56846deba2aa0
tree    9f3618ec7b5ff3e883b3dd4aa15b230310b2740f
parent  af8a7b8f7a316e2231358eeef16218baf42e506a
rails-settings /
name age
history
message
file .gitignore Thu Dec 24 16:18:01 -0800 2009 Updated readmem install instructions, added gem... [Squeegy]
file MIT-LICENSE Fri Feb 24 17:28:57 -0800 2006 git-svn-id: http://beautifulpixel.com/svn/plugi... [squeegy]
file README.rdoc Thu Dec 24 16:20:16 -0800 2009 . [Squeegy]
file Rakefile Thu Dec 24 16:07:55 -0800 2009 Gemmified plugin [Squeegy]
file VERSION Thu Dec 24 16:07:55 -0800 2009 Gemmified plugin [Squeegy]
directory generators/ Mon Dec 14 11:18:00 -0800 2009 Added index to migration, since lookups are key... [joshuaclayton]
file init.rb Thu Dec 24 16:07:55 -0800 2009 Gemmified plugin [Squeegy]
directory lib/ Sat Apr 12 15:03:08 -0700 2008 Modernized code a bit, and got tests passing. ... [Squeegy]
file rails-settings.gemspec Thu Dec 24 16:20:16 -0800 2009 . [Squeegy]
directory test/ Thu Dec 24 16:07:55 -0800 2009 Gemmified plugin [Squeegy]
README.rdoc

Settings Plugin

Settings is a plugin that makes managing a table of global key, value pairs easy. Think of it like a global Hash stored in you database, that uses simple ActiveRecord like methods for manipulation. Keep track of any global setting that you dont want to hard code into your rails app. You can store any kind of object. Strings, numbers, arrays, or any object.

Installation

Install the rails-settings gem

  gem install rails-settings

And include the gem in your apps config

  config.gem 'rails-settings', :lib => 'settings'

Or install as a plugin if you must. But gems are cooler.

  ./script/plugin install git://github.com/Squeegy/rails-settings.git

Setup

You must create the table used by the Settings model. Simply run this command:

  ruby script/generate settings_migration

Now just put that migration in the database with:

  rake db:migrate

Usage

The syntax is easy. First, lets create some settings to keep track of:

  Settings.admin_password = 'supersecret'
  Settings.date_format    = '%m %d, %Y'
  Settings.cocktails      = ['Martini', 'Screwdriver', 'White Russian']
  Settings.foo            = 123

Now lets read them back:

  Settings.foo            # returns 123

Changing an existing setting is the same as creating a new setting:

  Settings.foo = 'super duper bar'

Decide you dont want to track a particular setting anymore?

  Settings.destroy :foo
  Settings.foo            # returns nil

Want a list of all the settings?

  Settings.all            # returns {'admin_password' => 'super_secret', 'date_format' => '%m %d, %Y'}

Set defaults for certain settings of your app. This will cause the defined settings to return with the Specified value even if they are not in the database. Make a new file in config/initializers/settings.rb with the following:

  Settings.defaults[:some_setting] = 'footastic'

Now even if the database is completely empty, you app will have some intelligent defaults:

  Settings.some_setting   # returns 'footastic'

That’s all there is to it!. Enjoy!

Blog | Support | Training | Contact | API | Status | Twitter | Help | Security
© 2010 GitHub Inc. All rights reserved. | Terms of Service | Privacy Policy
Powered by the Dedicated Servers and
Cloud Computing of Rackspace Hosting®
Dedicated Server