Reputation: 81
I have an array of integers made out of a string which is in this format:
@var.numbers= "1,2,3,4,5"
The integers are then split into an array by:
@var.numbers.split(",").map(&:to_i)
When printed into the console, the command above puts out an array like it should, but when the following is done:
@[email protected](",").map(&:to_i)
After this command the @var.numbers2
outputs only 0. It doesn't even show up in array format over the console. Just plain 0. The @var.numbers
is an attr_accessor
and @var.numbers2
is defined as integer in the db and is serialized as an array in the model. Could that be causing an issue ? I have an exact same thing done with ordinary string types and serialized into arrays and it works like a charm. Thanks for the help !
Upvotes: 0
Views: 45
Reputation: 5840
numbers2
needs to of type string and not integer. You can't put serialized attributes into an integer column.
Upvotes: 1