Trying to insert a ruby hash into a Postgres Database -
i have created hash scraped xml data have retrieved web. next task insert data postgresql database each key different column, , have drawn blank. appreciated. in advance.
temp = @ttc.css('vehicle').map |vehicle| { id: vehicle.attributes["id"].value, routetag: vehicle.attributes["routetag"].value, lat: vehicle.attributes["lat"].value, lon: vehicle.attributes["lon"].value } end
provided model name vehicle
, vehicles
table has columns named id
, routetag
, lat
, lon
, solution simple this:
@new_vehicle = vehicle.create(temp)
Comments
Post a Comment