开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜