[ rails ] store : persist hash data in one table column

class Whatever < ActiveRecord::Base

store :added_config,
 accessors: [:param1, :param2, :param3],
 coder: YAML

NOTE : You can set custom coder to encode/decode your serialized attributes to/from different formats. JSON, YAML, Marshal.

Rails console

whatever = Whatever.last
whatever.added_config = {"param1"=>"test"}

whatevers table will contains column `added_config`


We can also access with

whatever = Whatever.last


ref : http://api.rubyonrails.org/classes/ActiveRecord/Store.html


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s