For reasons that I can’t completely decrypt for now, I can no longer use ActiveSupport :: HashWithIndifferentAccess.
The relevant part of the model is as follows:
class Item < ActiveRecord::Base
serialize :metadata, ActiveSupport::HashWithIndifferentAccess
(I added a parameter to try to force it, but that didn't help. Previously, all this worked fine, and I didn't have it there.)
While the object is in memory, everything is working fine. This is the correct HashWithIndifferentAccess, and life is good. Once it is saved to the database, it will be saved instead of 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 |
+----+------+-------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-------------+
This means that it cannot be forcibly returned to HashWithIndifferentAccess, and everything is fine:
ActiveRecord::SerializationTypeMismatch in Index
Showing /development/lists.io/website/app/views/users/_todo.html.haml where line
Attribute was supposed to be a ActiveSupport::HashWithIndifferentAccess, but was a Hash
Rails 3.1.3, MySQL, mysql2 gem 0.3.10. ruby 1.9.2p290. , , , .