Skip to content

scottatron/stored_attribute

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

stored_attribute Build Status

A simple extension to ActiveRecord for type casting serialized stored attributes using the store (introduced in Rails 3.2.0) method.

Usage

Add to your Gemfile:

gem 'stored_attribute'

Example code

class Post < ActiveRecord::Base
  store :data, :accessors => [:show_date, :show_author, :background_color]

  attribute :show_date,         :type => :boolean,  :default => false
  attribute :show_author,       :type => :boolean,  :default => true
  attribute :background_color,  :type => :string,   :default => '#FFFFFF'
end

post = Post.create
post.show_date # => false

post.update_attributes({ :show_date => true })
post.show_date # => true

About

ActiveRecord extension for type casting serialized attributes

Resources

Stars

Watchers

Forks

Packages

No packages published