开发者

Rails: Ignore nested attributes with a certain name?

开发者 https://www.devze.com 2023-02-15 10:22 出处:网络
Basing this functionality off of Ryan Bates Nested Model Form tutorials, when I submit my form, I\'ve got this set of data that\'s submitted:

Basing this functionality off of Ryan Bates Nested Model Form tutorials, when I submit my form, I've got this set of data that's submitted:

{
    "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"
    }
}

What I need to figure out how to do is ignore the new_qu开发者_如何学编程estions section. I know you can add reject_if to accepts_nested_attributes_for but there are hidden fields that are included and pre-populated with data, so I can't ignore based on empty fields.

So how can ignore new_questions in my example data?

I'm running Rails 3.0.3


i would look into using conditional validation. heres a railscast on it dealing with passwords, but you can easily adapt something similar for your situation

0

精彩评论

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

关注公众号