This repository is private.
All pages are served over SSL and all pushing and pulling is done over SSH.
No one may fork, clone, or view it unless they are added as a member.
Every repository with this icon (
) is private.
Every repository with this icon (
This repository is public.
Anyone may fork, clone, or view it.
Every repository with this icon (
) is public.
Every repository with this icon (
squeegy (author)
Tue Apr 18 15:41:50 -0700 2006
commit a8017dc5e6a573833b4543ceec81152ec1112b37
tree 966594fe232205883bae16ebab021c8dc0919474
parent 4dfc640cff6bc2c9a4a122485dbc8d89d9fa1b48
tree 966594fe232205883bae16ebab021c8dc0919474
parent 4dfc640cff6bc2c9a4a122485dbc8d89d9fa1b48
| name | age | message | |
|---|---|---|---|
| |
MIT-LICENSE | Fri Feb 24 17:28:57 -0800 2006 | [squeegy] |
| |
README | Tue Apr 18 15:41:50 -0700 2006 | [squeegy] |
| |
generators/ | Fri Mar 03 10:38:40 -0800 2006 | [squeegy] |
| |
init.rb | Fri Feb 24 16:16:04 -0800 2006 | [squeegy] |
| |
lib/ | Tue Apr 18 15:34:46 -0700 2006 | [squeegy] |
| |
test/ | Thu Apr 13 00:48:58 -0700 2006 | [squeegy] |
README
Settings
Settings is a plugin that makes managing a table of global key, value pair 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.
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 = 'bar'
Now lets read them back:
Settings.foo # returns 'bar'
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 # Now gives a setting variable not found error.
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. Here is what you insert into your environment.rb
module SettingsDefaults
DEFAULTS = {
:setting_one => 'footastic',
:setting_two => 123.321
}
end
Settings.some_one #=> returns "footastic" even though no record is in the databse for "some_setting"
Settings.some_one = 'bar' # Database record is now created and 'bar' will be used instead of the default.
NOTE: the server must be restarted in order to see new default settings.
***
* To get started:
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 migrate
All there is to it!. Enjoy!
The migration generator gives you the following schema:
class AddSettingsTable < ActiveRecord::Migration
def self.up
create_table :settings, :force => true do |t|
t.column :var, :string, :null => false
t.column :value, :string, :null => true
t.column :created_at, :datetime
t.column :updated_at, :datetime
end
end
def self.down
drop_table :settings
end
end




