[英]Rails 3: “accepts_nested_attributes_for :reject_if” doesn't work
My UserQuestion model has many accepted_answers and accepts nested attributes for:accepted_answers我的UserQuestion model 有许多accepted_answers 并接受嵌套属性:accepted_answers
accepts_nested_attributes_for :accepted_answers, :reject_if => lambda { |a| ( a[:answer_id] == 0) }, :allow_destroy => true
My form sends the following parameters:我的表单发送以下参数:
"accepted_answers_attributes"=>{"0"=>{"answer_id"=>"0"}, "1"=>{"answer_id"=>"25"}, "2"=>{"answer_id"=>"0"}}
I guess my problem is, that the lambda isn't set up right, because accepted answers are created even though their answer_id is 0我想我的问题是,lambda 设置不正确,因为即使它们的 answer_id 为 0 也会创建已接受的答案
try this:尝试这个:
:reject_if => lambda { |a| ( a[:answer_id].to_i == 0) }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.