Skip to content

saving array in database

January 18, 2011

So today I wanted to create a Model that would store an object to the database. In my situation the object was an Array.

Active record has the ‘serialize’ method that actually serializes the object when storing it on the database and unserializes it when pulling it out of the database.

http://api.rubyonrails.org/classes/ActiveRecord/Base.html#method-c-serialize

serialize has an optional object type that can be passed to it.

In the database, use the data type ‘text’ to match the attribute that needs to be stored on the database.

Advertisements

From → Uncategorized

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: