gpt4 book ai didi

ruby-on-rails - Rails 表单参数没有 "params"键

转载 作者:行者123 更新时间:2023-12-04 07:40:15 24 4
gpt4 key购买 nike

我的表单作为 PATCH 请求发布到正确的路由,但是在 ActionController::Parameters 中没有“params”键,它有一个包含调用表单的路径的键,这是我的表格:

<%= simple_form_for applicants_profile_path, method: :patch do |f| %>
<%= f.input :first_name %>
<%= f.button :submit, "submit" %>
<% end %>

当我的 Controller 收到请求时,参数有一个 url 而不是“params”

<ActionController::Parameters {"utf8"=>"✓", 
"_method"=>"patch",
"authenticity_token"=>"BI...f0EDQ==",
"/dashboard/profile"=>{
"first_name"=>"dfasfdsafs",
},
"commit"=>"submit",
"controller"=>"applicants/profile",
"action"=>"update"} permitted: false>

这是为什么?而不是 /dashboard/profile 它应该是 params 正确吗?

我还应该说这条路线是这样的“资源”路线:

resource :applicant, only: [ :show, :update ], as: :profile, path: 'profile', controller: 'profile'

最佳答案

答案实际上似乎与 simple_form 如何处理单一资源的路由有关,答案是将 url: applicants_profile_path 添加到我的表单助手中:

<%= simple_form_for @applicant, url: applicants_profile_path, method: :patch do |f| %>
<%= f.input :first_name %>
<%= f.button :submit, "submit" %>
<% end %>

关于ruby-on-rails - Rails 表单参数没有 "params"键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49562710/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com