简体   繁体   English

Rails 3:“accepts_nested_attributes_for:reject_if”不起作用

[英]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.

相关问题 Rails如何在accepts_nested_attributes_for时拒绝_if - Rails how to reject_if when accepts_nested_attributes_for rails accepts_nested_attributes_for:reject_if无效 - rails accepts_nested_attributes_for :reject_if not working 带reject_if的accepts_nested_attributes_for的定制属性版本 - custom attributes version of accepts_nested_attributes_for with reject_if rails accepts_nested_attributes和:reject_if - rails accepts_nested_attributes and :reject_if accepts_nested_attributes_for:reject_if触发另一个方法 - accepts_nested_attributes_for :reject_if to trigger another method accepts_nested_attributes_for和reject_if的回形针问题 - Paperclip problem for accepts_nested_attributes_for and reject_if 当使用双重嵌套关联时,reject_if: :all_blank for accepts_nested_attributes_for 如何工作? - How does reject_if: :all_blank for accepts_nested_attributes_for work when working with doubly nested associations? 有没有一种方法可以仅在创建时就为acpe强制执行accept_nested_attributes_for? - Is there a way to enforce reject_if for accep accepts_nested_attributes_for only on create? 如何在更新期间使用accepts_nested_attributes_for的reject_if选项删除子级 - How to delete child during update with reject_if option for accepts_nested_attributes_for accepts_nested_attributes_for,reject_if和has_one关系不能一起工作? - accepts_nested_attributes_for, reject_if and has_one relationship not working together?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM