我最近将一个旧的 Rails 2.3
应用程序 (Ruby 1.8.7) 升级到了 Rails 3.2/Ruby 1.9.3
。使用 ActiveRecord 序列化并尝试访问序列化属性时,我得到:
ActiveRecord::AttributeMethods::Serialization::Attribute returned.
.unserialize then returns the actual value.
真正奇怪的是,有一些模型具有正常行为。
有人可以帮助我吗?
最佳答案
我现在知道这个问题是什么时候发生的,但我仍然不知道为什么:
这个有效:
User < ActiveRecord::Base
serialize :options, Hash
end
选项返回{}
如果我在序列化之前调用模型本身,就像那样:
User < ActiveRecord::Base
USER_LIST = User.all.map {|u| [u.name, u.id]}
serialize :options, Hash
end
我得到 ActiveRecord::AttributeMethods::Serialization::Attribute
有人知道吗?
关于ruby - Rails 3 - 反序列化只返回 ActiveRecord::AttributeMethods::Serialization::Attribute,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15588643/