我不明白爲什麼有時候序列化生產這個(我想):Rails壞哈希序列化...有時候?
--- !map:ActiveSupport::HashWithIndifferentAccess
first_question: "Pas \xC3\xA9quilibr\xC3\xA9 -perte"
second_question: "Compte de r\xC3\xA9sultat"
有時是(我不希望):
---
first_question: ! "1- Mettre en place le renvoi de son téléphone vers sa boite vocale\r\n2-
Se mettre dans un bureau fermé pour travailler\r\n3- Savoir dire non"
second_question: ! "1- mes collègues\r\n2- le téléphone\r\n"
我最近做了一個新的部署和數據現在正在存儲中,不存在 !map:ActiveSupport :: HashWithIndifferentAccess部分,這是 破壞我的應用!
的Gemfile
ruby '1.9.2' # added this line 3 days ago...
gem 'rails', '3.1.10'
場模型
# encoding: utf-8
class Course < ActiveRecord::Base
# [...]
serialize :estart_scenario_data, Hash
# [...]
validate :validate_estart_scenario_data
# [...]
def add_data(prefix, params, is_done=true)
self["#{prefix}_data"] = params
self["#{prefix}_done_at"] = Time.now if is_done
end
# [...]
private
def validate_estart_scenario_data
unless self.estart_scenario_data.blank?
errors.add(:first_question, "Answer the first question") if self.estart_scenario_data[:first_question].blank?
errors.add(:second_question, "Answer the second question") if self.estart_scenario_data[:second_question].blank?
end
end
end
我用它來獲取值:
self.estart_scenario_data[:first_question]
現在它生產什麼。我必須改變:
self.estart_scenario_data["first_question"]
但是,它會產生一個錯誤「UTF-8中的無效字節序列」。
發生了什麼事? 現在我有2種哈希在數據庫中!
我該如何恢復?
紅寶石1.9.2p290壞序列化的一個實例存儲
params
,似乎有病有心理這裏有一個問題。我會在我的應用程序中嘗試'YAML :: ENGINE.yamler ='syck'' ... –