【发布时间】:2012-09-24 12:38:24
【问题描述】:
我最近为我的用户添加了一个“首选项”字段,该字段在我的 rails 应用程序中使用了 thw ActiveRecord 序列化方法。这适用于现有用户,但是当我尝试在控制台中初始化新用户模型时出现错误:
u = User.new
#=>
ActiveRecord::SerializationTypeMismatch: preferences was supposed to be a Hash, but was a String
我在迁移中添加了这样的字段:
add_column :users, :preferences, :text, :default => { :allows_public_contributions => false }.to_yaml
而在模型中,user.rb:
serialize :preferences, Hash
有什么想法吗?
【问题讨论】:
-
你的用户模型有回调吗?像 before_create 之类的?
标签: ruby-on-rails ruby-on-rails-3 activerecord serialization