簡體   English   中英

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

[英]Rails 3: “accepts_nested_attributes_for :reject_if” doesn't work

我的UserQuestion model 有許多accepted_answers 並接受嵌套屬性:accepted_answers

    accepts_nested_attributes_for :accepted_answers, :reject_if => lambda { |a| ( a[:answer_id] == 0) }, :allow_destroy => true

我的表單發送以下參數:

   "accepted_answers_attributes"=>{"0"=>{"answer_id"=>"0"}, "1"=>{"answer_id"=>"25"}, "2"=>{"answer_id"=>"0"}}

我想我的問題是,lambda 設置不正確,因為即使它們的 answer_id 為 0 也會創建已接受的答案

嘗試這個:

:reject_if => lambda { |a| ( a[:answer_id].to_i == 0) }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM