当使用 accepts_nested_attributes_for 时,我不想传递“child_attributes”,而是传递“child”。我很确定,如果我在我的 Controller 中放入大量逻辑来创建记录和子项,我就可以完成此操作。但是,为了使我的 Controller 保持干净和逻辑应有的位置,即本例中的模型,我想知道如何在执行 POST 或 PUT 时切换 rails 3 以使用此语法。
{
"name": "test",
"child_attributes": [
{
"id": 1,
"name": "test_child_update"
},
{
"name": "test_child_create"
}
}
相当
{
"name": "test",
"child": [
{
"id": 1,
"name": "test_child_update"
},
{
"name": "test_child_create"
}
}
最佳答案
显然,这是不可能的。
关于ruby-on-rails - Rails 3 如何允许在没有_attributes 指定的情况下传递嵌套属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11904800/