ruby-on-rails – 无法序列化为ActiveSupport :: HashWithIndiff
发布时间:2020-12-17 03:30:09 所属栏目:百科 来源:网络整理
导读:由于我到目前为止完全无法破译的原因,我不再能够使用ActiveSupport :: HashWithIndifferentAccess了. 模型的相关部分如下所示: class Item ActiveRecord::Base serialize :metadata,ActiveSupport::HashWithIndifferentAccess (我添加了尝试强制它的选项,但
由于我到目前为止完全无法破译的原因,我不再能够使用ActiveSupport :: HashWithIndifferentAccess了.
模型的相关部分如下所示: class Item < ActiveRecord::Base serialize :metadata,ActiveSupport::HashWithIndifferentAccess (我添加了尝试强制它的选项,但它没有帮助.以前这一切都工作正常,我没有那里.) 只要对象在内存中,一切正常.这是正确的HashWithIndifferentAccess,生活是美好的.一旦它被保存到数据库,它就会被保存为Hash: mysql> select * from items; +----+------+-------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-------------+ | id | link | text | metadata | category_id | +----+------+-------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-------------+ | 1 | NULL | Apple Store | --- id: 42cc7080f964a520e9251fe3 name: Apple Store contact: phone: '4153920202' formattedPhone: (415) 392-0202 location: address: 1 Stockton St. crossStreet: at Ellis St. lat: '37.78573590563453' lng: '-122.40610713227913' distance: '1784' postalCode: '94108' city: San Francisco state: CA country: USA categories: '0': id: 4bf58dd8d48988d122951735 name: Electronics Store pluralName: Electronics Stores shortName: Electronics icon: https://foursquare.com/img/categories/shops/technology.png parents: - Shops & Services primary: 'true' verified: 'false' stats: checkinsCount: '30462' usersCount: '16105' tipCount: '128' url: http://apple.com/sanfrancisco hereNow: count: '7' | 1 | +----+------+-------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-------------+ 这意味着它不能被强制回HashWithIndifferentAccess并且事情就像这样爆炸了: ActiveRecord::SerializationTypeMismatch in Index#index Showing /development/lists.io/website/app/views/users/_todo.html.haml where line #7 raised: Attribute was supposed to be a ActiveSupport::HashWithIndifferentAccess,but was a Hash 这是使用Rails 3.1.3,使用mysql2 gem版本0.3.10将数据存储在MySQL中.我也在运行ruby 1.9.2p290.我可以添加任何人认为有用的信息,但我不知道如何进一步调试. 解决方法
1.9.2通常包括Psych作为YAML库.但是,libyaml是一个外部依赖项,如果在编译Ruby时libyaml不可用,则1.9.2默认使用Syck(旧库):
link
Psych YAML-izes ActiveSupport :: HashWithIndifferentAccess作为标准哈希的事实是Psych的Github上的oustanding issue.似乎在1.9.3中已修复. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |