1
我有一個序列化問題。 在我的模型我有Rails並不反序列化陣列
class PramEntry < ActiveRecord::Base
serialize :pram_units_array, Array
attr_accessible :pram_units_array
end
然後我做
entry = PramEntry.new
entry.pram_units_array = [PramUnit.new(depth: 1, width: 1)]
entry.pram_units_array
=> [#<PramUnit:0x007fb368eb8ae8 @depth=1, @width=1>]
entry.save
=> true
但後來我從數據庫
entry = PramEntry.first
entry.pram_units_array
=> "---\n- &70364639756800 !ruby/object:PramUnit\n depth: 1\n width: 1\n errors: !ruby/object:ActiveModel::Errors\n base: *70364639756800\n messages: !omap []\n validation_context: \n"
加載這個對象時,它不會從YAML序列化回來。我做錯了什麼?提前致謝!