Forum: Ruby on Rails storing as YAML in the database

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Josh K. (Guest)
on 2007-08-02 22:09
(Received via mailing list)
i've got a project which i need to create some dynamic forms. each one
will be different so it seems almost impossible to keep a 1 to 1
relationship between each form field and a corresponding column in the
database.

i've heard that YAML is a lot faster than XML. would this be something
i can use or is there something else that anyone would recommend for
something like this?
Jason R. (Guest)
on 2007-08-02 22:38
(Received via mailing list)
Aye.

class MyThingy < AR::Base
  serialize :form_data
end

The form_data field will now be automatically saved as YAML text on
save/create, and pulled back out into valid Ruby objects.

For example:

MyThingy.create :form_data => {:one => 1, :two => 2}

becomes

one: 1
two: 2

Jason
Josh K. (Guest)
on 2007-08-02 23:01
(Received via mailing list)
oh man, that's perfect! i looked up serialize in the api and it says
that it will deserialize it when it is loaded. does that mean that
i'll also be able to do this?

my_thingy.form_data.one
my_thingy.form_data.two
Jacob A. (Guest)
on 2007-08-02 23:15
(Received via mailing list)
Josh wrote:
> oh man, that's perfect! i looked up serialize in the api and it says
> that it will deserialize it when it is loaded. does that mean that
> i'll also be able to do this?
>
> my_thingy.form_data.one
> my_thingy.form_data.two

No, it would be my_thingy.form_data[:one], but that's close enough.

--
Cheers,
- Jacob A.
This topic is locked and can not be replied to.