1

基于 Ryan Bates嵌套模型表单教程中的此功能,当我提交表单时,我收到了一组已提交的数据:

{
    "authenticity_token"=>"mdohADjieoqUwOwUK/H52TAiH5HdFYQtTbTuMJtDJE8=",
     "utf8"=>"✓",
     "id"=>"92",
     "survey"=>
    {
        "questions_attributes"=>
        {
            "1299616889104"=>
            {
                "display_type"=>"",
                 "text"=>"",
                 "other"=>"0",
                 "display_order"=>"0",
                 "answer_choices"=>"",
                 "item_type"=>"multiple_choice"
            },
             "new_questions"=>
            {
                "display_type"=>"compare",
                 "pick"=>"one",
                 "text"=>"",
                 "other"=>"0",
                 "display_order"=>"0",
                 "answer_choices"=>"",
                 "item_type"=>"compare"
            }
        },
         "id"=>"92"
    }
}

我需要弄清楚该怎么做是忽略该new_questions部分。我知道您可以添加reject_ifaccepts_nested_attributes_for但其中包含隐藏字段并预先填充了数据,因此我不能基于空字段忽略。

那么如何new_questions在我的示例数据中忽略呢?

我正在运行 Rails 3.0.3

4

1 回答 1

0

我会考虑使用条件验证。这是一个处理密码的railscast ,但你可以很容易地根据你的情况调整类似的东西

于 2011-03-08T21:31:52.030 回答