This project is archived and is in readonly mode.

#1055 ✓resolved
Matthew Moore

ActiveResource transfer of 'serialize :foo, Array' (YAML) attributes fails

Reported by Matthew Moore | September 16th, 2008 @ 12:39 AM | in 2.x

This is related to: Ticket 8555, but for serialized array data, not hash data.

When you have an ActiveRecord, like:


class Foo < ActiveRecord::Base
  serialize :bar, Array
end

If you assign a the values "1", "2", "3" to an instance of foo, here's the XML you get:


<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<foo>
  <created-at type=\"datetime\">2008-08-26T21:28:24Z</created-at>
  <bar type=\"yaml\">---
- \"1\"
- \"2\"
- \"3\"
</bar>
  <id type=\"integer\">1</id>
  <updated-at type=\"datetime\">2008-09-15T22:25:43Z</updated-at>
</foo>

However, when Active Resource tries to parse it, it gives the following ArgumentError error:

expected an attributes Hash, got "1"

/Library/Ruby/Gems/1.8/gems/activeresource-2.1.1/lib/active_resource/base.rb:891:in 'load'

Of course, this is because the only type of serialized data ActiveResource can currently handle is a serialized hash, not a serialized array.

Comments and changes to this ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

Referenced by

Pages