I created an array structure of hashes and i created a column in postgres to save that structure using the migration below
class AddKeyDirectionsToEvent < ActiveRecord::Migration[5.0]
def change
add_column :calendar_events, :key_directions, :text, array:true, default: []
end
end
now, the structure of the array is the one below
{
:in => [
[0] {
:duration => "5 mins",
:distance => "0.4 km",
:travel_mode => "WALKING",
:travel_type => nil
},
[1] {
:duration => "12 mins",
:distance => "5.3 km",
:travel_mode => "TRANSIT",
:travel_type => "SUBWAY"
},
[2] {
:duration => "9 mins",
:distance => "0.7 km",
:travel_mode => "WALKING",
:travel_type => nil
}
]
}
{
:out => [
[0] {
:duration => "10 mins",
:distance => "0.7 km",
:travel_mode => "WALKING",
:travel_type => nil
},
[1] {
:duration => "12 mins",
:distance => "5.3 km",
:travel_mode => "TRANSIT",
:travel_type => "SUBWAY"
},
[2] {
:duration => "6 mins",
:distance => "0.4 km",
:travel_mode => "WALKING",
:travel_type => nil
}
]
}
but for some reason in database it is saved like this
["{:in=>[{:duration=>\"5 mins\", :distance=>\"0.4 km\", :travel_mode=>\"WALKING\", :travel_type=>nil}, {:duration=>\"12 mins\", :distance=>\"5.3 km\", :travel_mode=>\"TRANSIT\", :travel_type=>\"SUBWAY\"}, {:duration=>\"9 mins\", :distance=>\"0.7 km\", :travel_mode=>\"WALKING\", :travel_type=>nil}]}", "{:out=>[{:duration=>\"10 mins\", :distance=>\"0.7 km\", :travel_mode=>\"WALKING\", :travel_type=>nil}, {:duration=>\"12 mins\", :distance=>\"5.3 km\", :travel_mode=>\"TRANSIT\", :travel_type=>\"SUBWAY\"}, {:duration=>\"6 mins\", :distance=>\"0.4 km\", :travel_mode=>\"WALKING\", :travel_type=>nil}]}"]
any ideas why? I tried chanign the type of array from :text, to :varchar and got same result. The only solution i found is using eval command to convert string back to array which is not ideal.