Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 以嵌套形式更新多个到多个关联_Ruby On Rails_Ruby_Ruby On Rails 5_Simple Form_Wicked Gem - Fatal编程技术网

Ruby on rails 以嵌套形式更新多个到多个关联

Ruby on rails 以嵌套形式更新多个到多个关联,ruby-on-rails,ruby,ruby-on-rails-5,simple-form,wicked-gem,Ruby On Rails,Ruby,Ruby On Rails 5,Simple Form,Wicked Gem,关于这个问题,我有三个模型。使用wickedgem进行多步骤注册 使用者 到AfterSignup#update def update @user = current_user @user.update_attributes(user_params) render_wizard @user end 我相信rails通过命名来处理关联的更新。但可能我弄错了,需要显式更新控制器中的关联。或者也许我没有正确命名物品 不管怎样,我都有点不清楚为什么个人资料没有更新 更新 当我尝试执行更新时

关于这个问题,我有三个模型。使用
wicked
gem进行多步骤注册

使用者 到
AfterSignup#update

def update
  @user = current_user
  @user.update_attributes(user_params)
  render_wizard @user
end
我相信rails通过命名来处理关联的更新。但可能我弄错了,需要显式更新控制器中的关联。或者也许我没有正确命名物品

不管怎样,我都有点不清楚为什么个人资料没有更新

更新 当我尝试执行更新时,控制台会记录
Unpermitted parameters::speciality\u id

<%= simple_form_for @user, url: wizard_path do |f| %>

  ...

  <%= simple_fields_for :profile_attributes do |cf| %>

    <%= cf.input :specialty_ids, collection: Role.order(:name), as: :grouped_select, group_method: :specialties, input_html: {multiple: true} %>

  <% end %>

  ...

<% end %>
我有这样定义的强参数

def user_params
  params.permit profile_attributes: [..., :specialty_ids]
end
更新2 这是完整的日志

Processing by AfterSignupController#update as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"...", "profile_attributes"=>{"specialty_ids"=>["", "22"], "commit"=>"Save and Continue", "id"=>"step_one"}
  User Load (0.7ms)  SELECT  "users".* FROM "users" WHERE "users"."id" = $1 ORDER BY "users"."id" ASC LIMIT $2  [["id", 52], ["LIMIT", 1]]
Unpermitted parameters: :specialty_ids
Unpermitted parameters: :utf8, :_method, :authenticity_token, :commit, :id
   (0.2ms)  BEGIN
  Profile Load (0.2ms)  SELECT  "profiles".* FROM "profiles" WHERE "profiles"."user_id" = $1 LIMIT $2  [["user_id", 52], ["LIMIT", 1]]
  SQL (0.4ms)  DELETE FROM "profiles" WHERE "profiles"."id" = $1  [["id", 110]]
  SQL (0.4ms)  INSERT INTO "profiles" ("user_id", "created_at", "updated_at") VALUES ($1, $2, $3) RETURNING "id"  [["user_id", 52], ["created_at", "2018-09-06 02:30:57.882173"], ["updated_at", "2018-09-06 02:30:57.882173"]]
   (0.5ms)  COMMIT
   (0.2ms)  BEGIN
   (0.2ms)  COMMIT
Redirected to http://localhost:3000/after_signup/requirements

您的强参数需要一个数组,因此您需要:

def user_params
  params.permit profile_attributes: [..., specialty_ids: []]
end

您的强参数需要一个数组,因此您需要:

def user_params
  params.permit profile_attributes: [..., specialty_ids: []]
end

整个控制台消息是什么,其中包含重要信息。您试图传递的参数在控制台中是什么样子的?params需要一个id数组吗?@Beartech我已经添加了完整的消息
params[:speciality\u IDs]
是一个数组。请尝试
params.permit profile_attributes:[…,speciality_id:[]]
整个控制台消息是什么,其中包含重要信息。您试图传递的参数在控制台中是什么样子的?params需要一个id数组吗?@Beartech我已经添加了完整的消息
params[:speciality\u IDs]
是一个数组。试试
params.permit profile\u attributes:[…,speciality\u id:[]]
ah,就在这里。比我想象的要简单得多。Params有时会让人痛苦。啊,就是这样。比我想象的要简单得多。Params有时会让人痛苦。
Processing by AfterSignupController#update as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"...", "profile_attributes"=>{"specialty_ids"=>["", "22"], "commit"=>"Save and Continue", "id"=>"step_one"}
  User Load (0.7ms)  SELECT  "users".* FROM "users" WHERE "users"."id" = $1 ORDER BY "users"."id" ASC LIMIT $2  [["id", 52], ["LIMIT", 1]]
Unpermitted parameters: :specialty_ids
Unpermitted parameters: :utf8, :_method, :authenticity_token, :commit, :id
   (0.2ms)  BEGIN
  Profile Load (0.2ms)  SELECT  "profiles".* FROM "profiles" WHERE "profiles"."user_id" = $1 LIMIT $2  [["user_id", 52], ["LIMIT", 1]]
  SQL (0.4ms)  DELETE FROM "profiles" WHERE "profiles"."id" = $1  [["id", 110]]
  SQL (0.4ms)  INSERT INTO "profiles" ("user_id", "created_at", "updated_at") VALUES ($1, $2, $3) RETURNING "id"  [["user_id", 52], ["created_at", "2018-09-06 02:30:57.882173"], ["updated_at", "2018-09-06 02:30:57.882173"]]
   (0.5ms)  COMMIT
   (0.2ms)  BEGIN
   (0.2ms)  COMMIT
Redirected to http://localhost:3000/after_signup/requirements
def user_params
  params.permit profile_attributes: [..., specialty_ids: []]
end