views:

50

answers:

1

Hi guys,

What is the best way to store array of of primitive types using Rails activerecord?

For example I've got article model, which has images property. Images property is array of image urls.

I don't wont use separate table to store this array.

Regards, Alexey Zakharov

A: 

You can use ActiveRecord::Base.serialize. It will save the object as YAML in database. You need to first create the column with :text or :string as its type.

class Article
  serialize :image_urls
end

article.image_urls = ['/images/image1.png', '/images/image2.png']
htanata
Great! I've dreamed about such feature when using asp.net mvc :)
Alexey Zakharov