cti*_*ide 5 ruby ruby-on-rails ruby-on-rails-3 ruby-on-rails-3.1
由于我到目前为止完全无法破译的原因,我不再能够使用ActiveSupport :: HashWithIndifferentAccess了.
模型的相关部分如下所示:
class Item < ActiveRecord::Base
serialize :metadata, ActiveSupport::HashWithIndifferentAccess
Run Code Online (Sandbox Code Playgroud)
(我添加了尝试强制它的选项,但它没有帮助.以前这一切都工作正常,我没有那里.)
只要对象在内存中,一切正常.这是正确的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 |
+----+------+-------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-------------+
Run Code Online (Sandbox Code Playgroud)
这意味着它不能被强制回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
Run Code Online (Sandbox Code Playgroud)
这是使用Rails 3.1.3,使用mysql2 gem版本0.3.10将数据存储在MySQL中.我也在运行ruby 1.9.2p290.我可以添加任何人认为有用的信息,但我不知道如何进一步调试.
| 归档时间: |
|
| 查看次数: |
3331 次 |
| 最近记录: |