我似乎无法使用该accepts_nested_attributes_for
命令删除项目,但我已根据本教程和相关的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
,没有任何反应。我检查了服务器输出并收到:
在 2013-07-16 16:15:16 -0400 为 127.0.0.1 启动 PATCH "/jobs/1"
JobsController#update 处理为 HTML
参数:{"utf8"=>"✓", "authenticity_token"=>"8VxYXujcKXpLEm8+7B43SLU6X3fH00kIOmFK+nvaBKs=", "job"=>{"name"=>"Cook", "description"=>"使food.", "specialties_attributes"=>{"2"=>{"name"=>"", "description"=>"", "_destroy"=>"1", "id"=>"3"} , "3"=>{"name"=>"", "description"=>"", "_destroy"=>"1", "id"=>"4"}}}, "commit"=>"更新作业", "id"=>"1"}
作业负载(0.1 毫秒) SELECT "jobs".* FROM "jobs" WHERE "jobs"."id" = ? 限制 1 [["id", "1"]]
不允许的参数:_destroy
不允许的参数:_destroy
不允许的参数:_destroy
不允许的参数:_destroy
我错过了什么?我已经阅读了教程和回购了很多次,但我看不出我在哪里走了。