使用Ruby App的HashWithIndifferentAccess问题

时间:2012-08-05 07:12:59

标签: ruby ruby-on-rails-3

我有两个与同一个数据库通信的应用程序。一个是Ruby on Rails应用程序,另一个是用Ruby编写的控制台应用程序。

在Rails应用程序中,我保存了一堆保存到名为“notification_settings”的列的设置。我的模型中有以下内容;

serialize :notification_settings, Hash

这会导致列中的值存储为

--- !map:ActiveSupport::HashWithIndifferentAccess 
test: !map:ActiveSupport::HashWithIndifferentAccess 
  email: "1"

当我在Ruby应用程序中执行相同操作时,哈希只是保存为普通哈希。即使我做了类似的事情; (在我的Ruby app model.rb中)

  hash = HashWithIndifferentAccess.new(self.notification_settings)
    hash[:test][:email] = 0
    self.update_attribute(:notification_settings, hash)

当我的Rails应用程序正在保存记录时,如何让Ruby应用程序以完全相同的方式保存记录(HashWithIndifferentAccess)?

0 个答案:

没有答案