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

时间:2022-04-02 01:15:57

I am using some tutorial to build some complex forms with nested attributes(project model and its nests attribute 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控制台中检查药丸的标签属性值时,就在提交之前,我得到一个正确的非空值...它怎么可能是

1 个解决方案

#1


3  

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 

#1


3  

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