我似乎无法使用删除项目accepts_nested_attributes_for
命令,但我已经按照本教程 http://railscasts.com/episodes/196-nested-model-form-revised以及相关的git repo https://github.com/railscasts/196-nested-model-form-revised/tree/master/questionnaire-after。我的模型是...
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
In my 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"=>"制作食物.", "specialties_attributes"=>{"2"=>{"name"=>"", "description"=>"", "_destroy"=>"1", "id"=>"3"}, "3"=>{"名称"=>"", "描述"=>"", "_destroy"=>"1", "id"=>"4"}}}, "提交"=>"更新工作”,“id”=>“1”}
作业负载 (0.1ms) SELECT "jobs".* FROM "jobs" WHERE "jobs"."id" = ?限制 1 [["id", "1"]]
不允许的参数:_destroy
不允许的参数:_destroy
不允许的参数:_destroy
不允许的参数:_destroy
我错过了什么?我已经浏览了很多次教程和回购协议,但我不知道我哪里出了问题。