This project is archived and is in readonly mode.
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
-
Matthew Moore September 16th, 2008 @ 12:41 AM
- Assigned user set to DHH
-
Matthew Moore September 16th, 2008 @ 02:16 AM
- 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.
-
Matthew Moore September 19th, 2008 @ 09:22 PM
- Assigned user changed from DHH to Michael Koziarski
- Tag changed from activeresource, patch, tested to activeresource, patch, tested
-
Michael Koziarski September 23rd, 2008 @ 01:09 PM
- Assigned user changed from Michael Koziarski to Rick
Any thoughts rick? I don't really use active resource so I've no idea / opinion
-
thesmith October 5th, 2008 @ 03:43 PM
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?
-
Repository October 5th, 2008 @ 06:29 PM
- 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 state:resolved] http://github.com/rails/rails/co...
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>
People watching this ticket
Attachments
Tags
Referenced by
- 1055 ActiveResource transfer of 'serialize :foo, Array' (YAML) attributes fails Signed-off-by: rick technoweenie@gmail.com [#1055 state:r...