我正在使用一些教程来构建一些具有嵌套属性的复杂表单(project
模型及其嵌套属性tags
)。问题是标签。我有这些意见:
<input id="project_title" name="project[title]" type="text">
和
<input id="project_tags_attributes_1383080749618_pill" name="project[tags_attributes][1383080749618][pill]" type="text" placeholder="add a tag" style="display: none;">
但提交表单时未设置任何标记属性。我的日志中有参数:
{"utf8"=>"✓", "authenticity_token"=>"4wly3xgZ3ge6pEc8pJAV0XPGbex0WJKoaQ8lVaoDNNA=", "project"=>{"title"=>"some_project", "tags_attributes"=>{"1383080749618"=>{"pill"=>""}}, "description"=>"descriptor"}, "commit"=>"Create project"}
奇怪的是,当我在Chrome控制台中检查药丸的标签属性值时,就在提交之前,我得到一个正确的非空值...它怎么可能
答案 0 :(得分:3)
我也遇到过这种问题。检查日志中是否没有未经许可的哈希。如果是这样,请在项目控制器中设置:
def project_params
params.require(:dee).permit(:title, :description, tags_attributes: [:pill])
end