Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

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

#1055

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.

Reported by Matthew Moore · September 16th, 2008 @ 12:39 AM

State: resolved
Milestone: 2.x
Assigned to: Rick Rick
Importance: none

Activity

  1. Matthew Moore
  2. Matthew Moore
    Matthew Moore
    • Tag changed from activeresource to activeresource, patch, tested

    Here's a patch that allows for loading of arrays of strings, as opposed to arrays of hashes. This is a fairly general solution that covers the scenario where the the seralized attribute is an Array of strings.

    September 16th, 2008 @ 02:16 AM

  3. Matthew Moore
    Matthew Moore
    • Assigned user changed from DHH to Michael Koziarski
    • Tag changed from activeresource, patch, tested to activeresource, patch, tested

    September 19th, 2008 @ 09:22 PM

  4. Michael Koziarski
    Michael Koziarski
    • Assigned user changed from Michael Koziarski to Rick

    Any thoughts rick? I don't really use active resource so I've no idea / opinion

    September 23rd, 2008 @ 01:09 PM

  5. thesmith
    thesmith

    Has there been any movement with this? I have tested the patch against a track.search feed from last.fm and it stops ActiveResource from raising an exception on multiple leaf elements.

    What release will this be part of?

    October 5th, 2008 @ 03:43 PM

  6. Repository
    Repository
    • State changed from new to resolved

    (from [4df45d86097efbeabceecfe53d8ea2da9ccbb107]) ActiveResource can load array of strings, like serialize :bar, Array

    Signed-off-by: rick technoweenie@gmail.com [#1055 ActiveResource transfer of 'serialize :foo, Array' (YAML) attributes fails state:resolved] http://github.com/rails/rails/co...

    October 5th, 2008 @ 06:29 PM