Can't store array in json field in postgresql (rails) can't cast Array to json
- by Drew H
This is the error I'm getting when I run db:migrate
rake aborted!
can't cast Array to json
This is my table
class CreateTrips < ActiveRecord::Migration
def change
create_table :trips do |t|
t.json :flights
t.timestamps
end
end
end
This is in my seeds.rb file
flights = [{
depart_time_hour: 600,
arrive_time_hour: 700,
passengers: [
{
user_id: 1,
request: true
}
]
}]
trip = Trip.create(
{
name: 'Flight',
flights: flights.to_json
}
)
For some reason I can't do this. If I do this.
trip = Trip.create(
{
name: 'Flight',
flights: { flights: flights.to_json }
}
)
It works. I don't want this though because now I have to access the json array with trip.flights.flights. Not the behavior I'm wanting.