0

我不明白为什么有时序列化会产生这个(我想要):

--- !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 部分,这破坏了我的应用程序!

宝石文件

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 中的无效字节序列”。

发生了什么?现在我在数据库中有两种哈希!

我怎样才能恢复这个?

4

2 回答 2

0

psyck并且ruby 1.9.2打得不好。我不得不升级到ruby 1.9.3.

于 2013-07-11T09:23:42.253 回答
0

--- !map:ActiveSupport::HashWithIndifferentAccess表示这是一个实例ActiveSupport::HashWithIndifferentAccess,第二个表示它是一个实例Hash

你可能params从你的控制器存储,这是一个实例ActiveSupport::HashWithIndifferentAccess

于 2013-07-11T10:35:12.237 回答