Ruby on rails Can';t似乎提交集合\u选择并接收未经许可的参数::hero\u id
对不起,这是我第一次发帖。我一直试图让这个集合提交工作,但每次我按下CreateReport按钮,它就会返回到屏幕,并在rails服务器终端中显示未经允许的参数::hero_id 模型 控制台Ruby on rails Can';t似乎提交集合\u选择并接收未经许可的参数::hero\u id,ruby-on-rails,collection-select,Ruby On Rails,Collection Select,对不起,这是我第一次发帖。我一直试图让这个集合提交工作,但每次我按下CreateReport按钮,它就会返回到屏幕,并在rails服务器终端中显示未经允许的参数::hero_id 模型 控制台 (byebug) params.require(:report) <ActionController::Parameters {"subject"=>"Test report", "description"=>"Tes
(byebug) params.require(:report)
<ActionController::Parameters {"subject"=>"Test report", "description"=>"Test report", "hero_ids"=>"1"} permitted: false>
(byebug)参数要求(:报告)
“测试报告”、“描述”=>“测试报告”、“英雄ID”=>“1”}允许:false>
显示服务器控制台中显示的参数。这些参数不是控制台中显示的参数。这是一个报告
实例。另外,请将控制台输出编辑为原始问题。注释中的代码和其他信息不是一件好事。谢谢你的提示。我想我添加了您要求的内容。注意发送过来的参数中如何显示hero\u id
?如果是该字段,则将其更改为与白名单参数中的字段匹配(hero\u id
=>hero\u id
)@RockwellRice-需要将hero\u id:[]
转换为hero\u id
,是吗<代码>英雄ID:[]仍然不正确。另外,当参数中显然没有hero\u id
时,为什么控制台会读“Unpermitted parameter::hero\u id”?显示服务器控制台中显示的参数。这些参数不是控制台中显示的参数。这是一个报告
实例。另外,请将控制台输出编辑为原始问题。注释中的代码和其他信息不是一件好事。谢谢你的提示。我想我添加了您要求的内容。注意发送过来的参数中如何显示hero\u id
?如果是该字段,则将其更改为与白名单参数中的字段匹配(hero\u id
=>hero\u id
)@RockwellRice-需要将hero\u id:[]
转换为hero\u id
,是吗<代码>英雄ID:[]仍然不正确。另外,当参数中显然没有hero\u id
时,为什么控制台会读取“Unpermitted parameter::hero\u id”?
<div class="container">
<div class="row justify-content-center">
<div class="col-10">
<% if @report.errors.any? %>
<h2>The following errors prevented the article from being saved</h2>
<ul>
<% @report.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
<% end %>
<%= form_with(model: @report, class: "shadow p-3 mb-3 bg-dark rounded", local: true) do |f| %>
<div class="form-group row">
<%= f.label :subject, class: "col-2 col-form-label text-light" %>
<div class="col-10">
<%= f.text_field :subject, class: "form-control shadow rounded", placeholder: "Subject of Report" %>
</div>
</div>
<div class="form-group row">
<%= f.label :description, class: "col-2 col-form-label text-light" %>
<div class="col-10">
<%= f.text_area :description, rows: 10, class: "form-control shadow rounded", placeholder: "Description of Issue" %>
</div>
</div>
<div class="form-group row">
<%= f.label :hero, class: "col-2 col-form-label text-light" %>
<div class="col-10">
<%= f.collection_select(:hero_ids, Hero.all, :id, :hero_name, {prompt: "Select a Hero"}, {:required => true}) %>
</div>
</div>
<div class="btn-toolbar p-2 mb-2 row justify-content-center">
<%= f.submit class: "btn btn-primary" %>
</div>
<% end %>
</div>
<div class="mb-3">
<%= link_to '[ Cancel and return to reports listing ]', reports_path, class: "text-info" %>
</div>
</div>
</div>
def report_params
#byebug
params.require(:report).permit(:subject, :description, hero_ids: [])
end
(byebug) params.require(:report)
<ActionController::Parameters {"subject"=>"Test report", "description"=>"Test report", "hero_ids"=>"1"} permitted: false>