Ruby on rails 3 在输入前读取属性;似乎无法使用序列化:
我的Rails应用程序中有以下模型,它使用JSON编解码器进行序列化。我的数据库列的类型为“text”Ruby on rails 3 在输入前读取属性;似乎无法使用序列化:,ruby-on-rails-3,activerecord,Ruby On Rails 3,Activerecord,我的Rails应用程序中有以下模型,它使用JSON编解码器进行序列化。我的数据库列的类型为“text” class Sample < ActiveRecord::Base serialize :face_detect, JSON end 我期待一个“String”类,因为我期待“before_type_cast”,也意味着在序列化之前,但我得到的是“Hash”类。这怎么可能 (使用rvm,使用ruby-1.9.2-p290和rails(3.1.3)以及Mac OSX上的postgre
class Sample < ActiveRecord::Base
serialize :face_detect, JSON
end
我期待一个“String”类,因为我期待“before_type_cast”,也意味着在序列化之前,但我得到的是“Hash”类。这怎么可能
(使用rvm,使用ruby-1.9.2-p290和rails(3.1.3)以及Mac OSX上的postgresql)序列化在Arel内部进行得非常深入,但我可以访问预序列化值,如下所示:
@sample.instance_variable_get("@attributes")["face_detect"].serialized_value
对于Rails 4:
@attributes['data'].serialized_value
在Rails 4中对我不起作用。
@Attributes
中的属性值已从数据库反序列化。
@attributes['data'].serialized_value