如何允许数组 json 和 Rails?
How to permit an array json with Rails?
对于json
{
"version":"1",
"configs":[
{
"title":"Good",
"body":"Body"
},
{
"title":"Good",
"body":"Body"
}
]
}
如何在控制器中使用 Rails' params.permit
允许它?
我试过了
params.permit(
config_setting: [
:version,
configs: [
:title,
:body,
]
],
)
但好像不对
目前您允许 json 具有以下结构:
{
"config_setting": [
{
"version":"1",
"configs":[
{
"title":"Good",
"body":"Body"
},
{
"title":"Good",
"body":"Body"
}
]
}
]
}
只需将 config_setting
节点添加到数据或将强参数块调整为:
params.permit(
:version,
configs: [
:title,
:body,
]
)
对于json
{
"version":"1",
"configs":[
{
"title":"Good",
"body":"Body"
},
{
"title":"Good",
"body":"Body"
}
]
}
如何在控制器中使用 Rails' params.permit
允许它?
我试过了
params.permit(
config_setting: [
:version,
configs: [
:title,
:body,
]
],
)
但好像不对
目前您允许 json 具有以下结构:
{
"config_setting": [
{
"version":"1",
"configs":[
{
"title":"Good",
"body":"Body"
},
{
"title":"Good",
"body":"Body"
}
]
}
]
}
只需将 config_setting
节点添加到数据或将强参数块调整为:
params.permit(
:version,
configs: [
:title,
:body,
]
)