开发者

Rails 3: "accepts_nested_attributes_for :reject_if" doesn't work

开发者 https://www.devze.com 2023-03-28 02:58 出处:网络
My UserQuestion model has many accepted_answers and accepts nested attributes for :accep开发者_运维百科ted_answers

My UserQuestion model has many accepted_answers and accepts nested attributes for :accep开发者_运维百科ted_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


try this:

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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号