繁体   English   中英

尝试将红宝石哈希值插入Postgres数据库

[英]Trying to insert a ruby hash into a Postgres Database

我已经从网上检索到的抓取的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表中的列命名为idrouteTaglatlon ,你的解决方案是如此简单:

@new_vehicle = Vehicle.create(temp)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM