After struggling with this for hours, I think I've finally developed a solution to the following problem. I have the code here: http://pastie.org/767503 . What I am doing is allowing for classic http modification of a logic expression like
(OR (AND ItemsFromCollectionPredicate) (AND TruePredicate))
which is the params hash below
"condition"=>{
"or_clause_attributes"=>{"position"=>"2", "id"=>"98",
"and_clauses_attributes"=>{
"0"=>{"condition_predicates_attributes"=>{
"0"=>{"quantifier"=>"==", "position"=>"1", "pred_type"=>"ItemsFromCollectionPredicate", "quota"=>"0", "apply_to_OTAK"=>"false", "id"=>"113", "item_collection_id"=>"", "_destroy"=>""},
"1"=>{"position"=>"2", "pred_type"=>"TruePredicate", "id"=>"114", "_destroy"=>"1"}
}, "id"=>"102",
}}, "id"=>"6"}
When I save, this generates a validation error for the ItemsFromCollectionPredicate, and the destruction gets marked for the TruePredicate.
The question is: Is there a better method for doing the following?
To keep dangling nodes from existing, I'm using before_validation callbacks to determine if a parent ConditionClause should be marked for deletion. This is needed because the whole nested model is validated before any saves, so propagating marks_for_destruction up the chain has to happen there afaict.
In the view I set style="display:none;" for the enclosing block for any model marked for destruction. This ensures that the template for that model won't show up in the view.