0

I am building a web app using Rails and Postgres. I am trying to save an array into my database table and it is only deleting the last value in the array.

For example if my array is:

a= [10,12,14,16]

I would do @table.column = a.json

When I do byebug a.json = [10,12,14,16] however if I get the value of @table.column it is equal to [10,12,14]. This happens for all arrays I save to my database.

The column schema is:

t.text "name", default: [], array: true

Screenshot of byebug for my code

1 Answer 1

1

Try the serialize instance public method, so in your model do :

serialize :steves_journey_passed, Array

Then, retry to save your array without .to_json method.

I hope it helped you !

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.