No commit activity in last 3 years
No release in over 3 years
A key value store controller for Rails models
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies
 Project Readme

The Nifty Key Value Store

If you want to create a quick key/value store in your application where the values relate to an existing model, this is very helpful.

Add the gem to the Gemfile

gem "nifty-key-value-store", require: "nifty/key_value_store"

You'll need to create the database table and then, once added, you can specify what objects you want to store.

$ rails generate nifty:key_value_store:migration
$ rake db:migrate
class Person < ActiveRecord::Base
  key_value_store :settings
  key_value_store :other_settings
end

person = Person.new
person.settings             = {:colour => 'red', :fruit => 'apple'}
person.other_settings_json  = "{"hello":"world"}"
person.save

person = Person.find(person.id)
person.settings         #=> {'colour' => 'red', 'fruit' => 'apple'}
person.settings_json    #=> "{'color':'red', 'fruit':'apple'}"

A few points to note about this:

  • All values are stored as strings in the database
  • All keys are stored as strings and returned as strings in their hash