Rails: Ignore nested attributes with a certain name?
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
精彩评论