Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Ruby gem to handle settings for ActiveRecord objects by storing them as serialized Hash in a separate database table. Optional: Defaults and Namespaces.
tree: adb712b203

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
ci
lib
spec
.gitignore
.travis.yml
Changelog.md
Gemfile
MIT-LICENSE
README.md
Rakefile
rails-settings.gemspec

README.md

Settings gem for Rails

Build Status

Handling settings for ActiveRecord objects by storing them as serialized Hash in a separate database table. Optional: Defaults and Namespaces.

BEWARE: WORK IN PROGRESS!

Requirements

Rails 3.1.x or 3.2.x
Ruby 1.8.7, 1.9.3 or 2.0.0

Example

Define Settings for a model with default values

class User < ActiveRecord::Base
  has_settings :dashboard => { :theme => 'blue', :view => 'monthly', :filter => false },
               :calendar  => { :scope => 'company'}
end

Set settings for a given object

user = User.find(1)
user.settings(:dashboard).theme = 'black'
user.settings(:calendar).scope = 'all'
user.settings(:calendar).display = 'daily'
user.save!

or

user = User.find(1)
user.settings(:dashboard).update_attributes! :theme => 'black'
user.settings(:calendar).update_attributes! :scope => 'all', :display => 'dialy'

Get settings

user = User.find(1)
user.settings(:dashboard).theme
# => 'black

user.settings(:dashboard).view
# => 'monthly'  (it's default)

user.settings(:calendar).scope
# => 'all'

Installation

Include the gem in your Gemfile:

gem 'ledermann-rails-settings', :github => 'ledermann/rails-settings', :branch => 'rewrite', :require => 'rails-settings'

Generate and run the migration:

rails g rails_settings:migration
rake db:migrate

License

MIT License
Copyright (c) 2013 Georg Ledermann

This gem is a complete rewrite of rails-settings by Alex Wayne

Something went wrong with that request. Please try again.