简体   繁体   English

在rails中使用嵌套属性的表单

[英]forms with nested attributes in rails

I am using some tutorial to build some complex forms with nested attributes( project model and its nests attribute tags ). 我正在使用一些教程来构建一些具有嵌套属性的复杂表单( project模型及其嵌套属性tags )。 The problem is tag. 问题是标签。 I have those inputs : 我有这些投入:

<input id="project_title" name="project[title]" type="text">

and

<input id="project_tags_attributes_1383080749618_pill" name="project[tags_attributes][1383080749618][pill]" type="text" placeholder="add a tag" style="display: none;">

but no tag attribute is set when submitting the form. 但是在提交表单时没有设置标签属性。 I have in my log Parameters: 我在我的日志中有参数:

{"utf8"=>"✓", "authenticity_token"=>"4wly3xgZ3ge6pEc8pJAV0XPGbex0WJKoaQ8lVaoDNNA=", "project"=>{"title"=>"some_project", "tags_attributes"=>{"1383080749618"=>{"pill"=>""}}, "description"=>"descriptor"}, "commit"=>"Create project"}

What is weird is that when I check the pill's tag attribute value in my chrome console, just before submitting, I get a correct non null value... How can it be 有点奇怪的是,当我在我的Chrome控制台中检查药丸的标签属性值时,就在提交之前,我得到一个正确的非空值......它怎么可能是

I have also ran into that kind of issue. 我也遇到过这样的问题。 Check if you don't have an unpermitted hash in your logs. 检查日志中是否没有未经许可的哈希。 If so, set in your project controller : 如果是这样,请在项目控制器中设置:

def project_params
  params.require(:dee).permit(:title, :description, tags_attributes: [:pill])
end 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM