由於我迄今完全無法破譯的原因,我不再能夠使用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 version 0.3.10在MySQL中存儲數據。我也運行紅寶石1.9.2p290。我可以添加任何人都會認爲有用的信息,但是我對如何進一步調試這個問題感到茫然。