Last active
August 3, 2019 06:04
-
-
Save notEthan/84a4e583ea6e96f0f92dab43286ba301 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Setup | |
require 'active_record' | |
require 'arms' | |
ActiveRecord::Base.establish_connection( | |
:adapter => "sqlite3", | |
:database => "foos.sqlite3" | |
) | |
ActiveRecord::Schema.define do | |
create_table :foos do |table| | |
table.column :preferences, :string | |
end | |
end | |
class Foo < ActiveRecord::Base | |
arms_serialize :preferences, :indifferent_hashes, ::JSON | |
end | |
# Runtime | |
Foo.create!(preferences: {favorite_animal: 'ocelot'}) | |
foo = Foo.last | |
puts foo.preferences_before_type_cast | |
puts foo.preferences[:favorite_animal] | |
puts foo.preferences['favorite_animal'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment