ube*_*eit 8 json ruby-on-rails polygon geojson strong-parameters
这个问题部分回答了我的问题.作者使用类似的json结构..
我的问题:如何在嵌套对象中允许嵌套数组?我有一个Contribution模特has_many Features.我正在尝试创建GeoJSON多边形.在coordinates保持为空
这是我发送的JSON
{
"contribution": {
"features_attributes": [
{
"geojson": {
"type": "Feature",
"properties": {},
"geometry": {
"type": "Polygon",
"coordinates": [
[
[
7.263336181640625,
52.07190953840937
],
[
7.263336181640625,
52.135173926548894
],
[
7.404785156249999,
52.135173926548894
],
[
7.404785156249999,
52.07190953840937
],
[
7.263336181640625,
52.07190953840937
]
]
]
}
}
}
],
"title": "324",
"description": "23"
}
}
Run Code Online (Sandbox Code Playgroud)
目前我的许可证代码如下:
params.require(:contribution).permit(
:title,
:description,
features_attributes: [
{ geojson: [
:type,
{ geometry: [
:type,
#{ coordinates: [] } # this works for arrays like coordinates: [ 7.62, 51.96 ]
{ coordinates: [[]] }
]
}
]
}
]
)
Run Code Online (Sandbox Code Playgroud)
我现在这样解决了.请指正!:)
params.require(:contribution).permit(
:title,
:description,
features_attributes: [
{
geojson: [
:type,
{ geometry: [
:type,
{ coordinates: [] },
coordinates: []
]
}
]
}
]
).tap do |whitelisted|
whitelisted['features_attributes'].try(:each_index) do |i|
whitelisted['features_attributes'][i]['geojson']['geometry']['coordinates'] = params['contribution']['features_attributes'][i]['geojson']['geometry']['coordinates']
end
end
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3376 次 |
| 最近记录: |