Why does ActiveRecord leave the last element when parsing a string as data for an array attribute?

I am using Postgres. I have an ActiveRecord model with an integer column, for example:

t.integer "foo", array: true 

If I assign a ruby ​​array to it, it will work as expected:

 > @instance.foo = [6,7,8,9,1] > @instance.foo => [6, 7, 8, 9, 1] 

However, if I give a string representation of this array, it tries to parse the data, but for some reason it always leaves the last element.

 > @instance.foo = "[6,7,8,9,1]" > @instance.foo => [6, 7, 8, 9] 

Why is this happening?

+5
source share

Source: https://habr.com/ru/post/1260607/


All Articles