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
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']
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With