我根据从网络上检索到的抓取的 xml 数据创建了这个散列。我的下一个任务是将这些数据插入到 postgresql 数据库中,其中每个键都是不同的列,我已经画了一个空白。任何帮助表示赞赏。提前致谢。
temp = @ttc.css('vehicle').map do |vehicle|
{
id: vehicle.attributes["id"].value,
routeTag: vehicle.attributes["routeTag"].value,
lat: vehicle.attributes["lat"].value,
lon: vehicle.attributes["lon"].value
}
end
最佳答案
假设您的模型名称是 Vehicle
并且您的 vehicles
表包含名为 id
、routeTag
、lat
, lon
,您的解决方案会像这样简单:
@new_vehicle = Vehicle.create(temp)
关于ruby-on-rails - 尝试将 ruby 哈希插入 Postgres 数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31588690/