Walter Lee Davis
2011-Jan-06 22:15 UTC
Can I force an update to nested attributes to always save new children?
I have a Rails 2.3.10 application like this: Campaign has one or many AdUnits which each have one or many Ads. (Each ad has a file attached to it with Paperclip.) I currently have vestal_versions on the Ads, which allows me to track the history of an ad as it moves through the approval process. But now the client would like me to move versions up to the AdUnit level, and vestal_versions doesn''t track associated records like this. I had the bright idea of rigging the AdUnit#update method so that instead of updating the nested Ads, it would create and link new Ads. Then I could update my version record with a hash or array of the new ad_id values within that AdUnit and use that array to re-find the correct children whenever I need to display an older version. This would also get around Paperclip''s insistence on deleting the previous version of an attached file whenever you update an existing record. (I currently have that monkey-patched so it keeps everything and appends the filename with the version id.) So, is this over-thinking things? If not, how would you do this? On the other hand, is there another way to do this? The key requirement is that I be able to rewind an AdUnit to some point in the past, when it had different versions of the same N ads and show the AdUnit as it stood at that point to a visitor; so I never want to throw away any ads or their Paperclipped file attachments, and I want each update of an AdUnit to create a new vestal_version that "knows" which N Ads belong to it. I realize this is kind of backwards of how these relationships usually work -- a child knows who its parent is, but the parent doesn''t store the child ids in its object (where they could become a part of the shadow version table). Thanks in advance, Walter -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.