Failed to serialize as ActiveSupport :: HashWithIndifferentAccess

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#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, MySQL, mysql2 gem 0.3.10. ruby ​​1.9.2p290. , , , .

+5
4

1.9.2 Psych YAML. libyaml , 1.9.2 Syck ( ), libyaml Ruby: link

, Psych YAML-izes ActiveSupport:: HashWithIndifferentAccess Psych Github. , 1.9.3, .

+4

-, 1.9.2-p290.

1.9.3, 1.8.7, . , , - .

+3

, syck.

application.rb:

require 'yaml'
YAML::ENGINE.yamler = 'syck'
0

- , , , , . , , db. JS, db, : ActiveSupport:: HashWithIndifferentAccess, . , eval. , . params, update_attributes , HashwithIndifferentAccess,

0

All Articles