This问题部分回答了我的问题.作者使用类似的json结构..
我的问题:如何在嵌套对象中允许嵌套数组?我有一个带有has_many功能的贡献模型.我正在尝试创建GeoJSON多边形.
坐标保持空白
这是我发送的JSON
{ "contribution": { "features_attributes": [ { "geojson": { "type": "Feature","properties": {},"geometry": { "type": "Polygon","coordinates": [ [ [ 7.263336181640625,52.07190953840937 ],[ 7.263336181640625,52.135173926548894 ],[ 7.404785156249999,52.07190953840937 ] ] ] } } } ],"title": "324","description": "23" } }
目前我的许可证代码如下所示:
params.require(:contribution).permit( :title,:description,features_attributes: [ { geojson: [ :type,{ geometry: [ :type,#{ coordinates: [] } # this works for arrays like coordinates: [ 7.62,51.96 ] { coordinates: [[]] } ] } ] } ] )
解决方法
我现在这样解决了.请指正!