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) }
精彩评论