All,
I have an Active Record column which I serialize into a Array of
Hashes, like below:
Model:
serialize :sizes
which, when accessed produces and structure like:
[{:quantity=>"1", :size=>1}, {:quantity=>"2",
:size=>2},
{:quantity=>"2", :size=>3}]
this gets converted into YAML when stored in the DB.
I am having problems representing this in my YAML test fixtures.
I have tried the following:
sizes: ''--- \n- :quantity: "1"\n :size: 1\n- :quantity:
"2"\n
:size: 2\n- :quantity: "2"\n :size: 3\n''
and
sizes: <%= [{:quantity=>"1", :size=>1},
{:quantity=>"2", :size=>2},
{:quantity=>"2", :size=>3}].to_yaml %>
to no avail.
Does anybody how one might represent such an array in YAML?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk
-~----------~----~----~----~------~----~------~--~---
quantity: - 1 - 2 - 3 -- Marcus Brito --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
To those who come along, I found the following solution:
sizes: [{!ruby/sym quantity: ''5'', !ruby/sym size: 1},
{!ruby/sym
quantity: ''8'', !ruby/sym size: 2}, {!ruby/sym quantity:
''8'', !ruby/sym
size: 3}]
see:
http://yaml4r.sourceforge.net/cookbook/#simple_inline_array
http://yaml4r.sourceforge.net/cookbook/#symbols
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk
-~----------~----~----~----~------~----~------~--~---
More generally, you can find out the yaml format for any data structure from the console: planb:/~ $ ./script/console Loading development environment. >> b = %w(eeny meeny miney mo) => ["eeny", "meeny", "miney", "mo"] >> require ''yaml'' => false >> puts b.to_yaml --- - eeny - meeny - miney - mo => nil >> quit (ignore the ''false'' after the require). On 04/09/06, Marcus Brito <mbrito-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > quantity: > - 1 > - 2 > - 3 > > -- Marcus Brito > > > > >-- Rasputin :: Jack of All Trades - Master of Nuns http://number9.hellooperator.net/ --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Awesome! Spent way too much time reading the YAML specification to try to make this work for me. Thanks for posting your solution and links. Jamie --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---