Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Storing an Array in rails 4 using sqlite

I'm looking to add a row to my "posts" database that can store an array that holds multiple user id's. I noticed that none of the other questions asked on here were using rails 4. I think that this is going to require me to serialize the information but I'm not sure how to do this.

thanks in advance!


1 Answers

Create a migration

rails g migration AddSomethingToPosts something:text

In your model add

serialize :something, Array

here is more info: http://apidock.com/rails/ActiveRecord/AttributeMethods/Serialization/ClassMethods/serialize

also you can use store -> http://api.rubyonrails.org/classes/ActiveRecord/Store.html, and it probably will be a better choice :)


Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!