ActiveRecord Json Serialize
ActiveRecord JSON serializer
Installation
Add this line to your application's Gemfile:
gem 'ar_json_serialize'
And then execute:
$ bundle
Or install it yourself as:
$ gem install ar_json_serialize
Usage
You need to have some text
field for storing some specific data in Hash/Array/etc inside you model.
Add next string in your ActiveRecord model:
class Promo < ActiveRecord::Base
json_serialize :test_column
end
You can set value of this column with any object.
promo = ::Promo.new
promo.test_column = {'key1' => 'value1'}
promo.save!
And use it with full power of Hashie!
promo = ::Promo.last
puts "Our value is #{promo.test_column.key1}"
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request