gpt4 book ai didi

ruby-on-rails - 删除嵌套属性不起作用

转载 作者:行者123 更新时间:2023-12-04 20:37:59 25 4
gpt4 key购买 nike

我似乎无法使用 accepts_nested_attributes_for 删除项目命令,但我已根据 this tutorial 完成此操作和相关的 git repo .我的模型是...

class Job < ActiveRecord::Base
has_many :specialties, :inverse_of => :job
accepts_nested_attributes_for :specialties, allow_destroy: true, :reject_if => :all_blank
end

class Specialty < ActiveRecord::Base
belongs_to :job, :inverse_of => :specialties
end
在我的 Job表格,我有...
<%= f.check_box :_destroy %>
<%= f.label :_destroy, "Remove Specialty" %>
当我点击复选框删除几个 specialties , 没发生什么事。我检查了服务器输出并收到:

Started PATCH "/jobs/1" for 127.0.0.1 at 2013-07-16 16:15:16 -0400

Processing by JobsController#update as HTML

Parameters: {"utf8"=>"✓", "authenticity_token"=>"8VxYXujcKXpLEm8+7B43SLU6X3fH00kIOmFK+nvaBKs=", "job"=>{"name"=>"Cook", "description"=>"Makes the food.", "specialties_attributes"=>{"2"=>{"name"=>"", "description"=>"", "_destroy"=>"1", "id"=>"3"}, "3"=>{"name"=>"", "description"=>"", "_destroy"=>"1", "id"=>"4"}}}, "commit"=>"Update Job", "id"=>"1"}

Job Load (0.1ms) SELECT "jobs".* FROM "jobs" WHERE "jobs"."id" = ? LIMIT 1 [["id", "1"]]

Unpermitted parameters: _destroy

Unpermitted parameters: _destroy

Unpermitted parameters: _destroy

Unpermitted parameters: _destroy


我错过了什么?我已经浏览了教程和 repo 了很多次,但我看不到我离开的地方。

最佳答案

那是因为 strong_parameters .您现在必须permit键。在你的行动中:
params.permit(:_destroy)

关于ruby-on-rails - 删除嵌套属性不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17686440/

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