I have the following model in my Rails app that uses serialization with JSON codec. My database columns are of the type ‘text’
class Sample < ActiveRecord::Base
serialize :face_detect, JSON
end
When I run the following in the rails console
Sample.first.read_attribute_before_type_cast('face_detect').class
I’m expecting a ‘String’ class, since I expect ‘before_type_cast’, also means before serialisation, but instead I get the ‘Hash’ class. How is this possible?
(using rvm, with ruby-1.9.2-p290 with rails (3.1.3) and postgresql on Mac OSX)
Serialization happens very deeply inside Arel, but I could access the pre-serialized value like this: