Julian ''Julik'' Tarkhanov
2005-Jun-30 15:21 UTC
Banging my head against the model - can anyone help?
Granted, this is not a question about bugs or something - I have a site I need to finish and I cannot invent a way to organize a model properly. The situation is as follows. I have a number of Templates and a number of Works. Every Work is assigned one of these templates. Every template defines a number of slots for images that should be uploaded for the Work to be valid. The trick here is that I would love to keep the templates as files (it''s more convenient for the designer that works with me) - but if I can define this slot information somewhere separately it''s OK. The problem is also that every slot has 2 images - a special prepared thumbnail (no autogen thumbnails here, this is a requirement) and the image which will appear in the popup. Another problem is that I need to accept (or replace) the images in one fell swoop from one form (i.e. from a typical edit/id page, where a Work is being edited). What I tried so far: Work that has_many Images, every Image has a thumbnail and a file - was clumsy, worked only somehow. Besides no matter what I did the images never got deleted when I deleted a Work, even though I specified :dependent=>true in the Work. Work that has_many Slots, whereas each Slot has an Image as a thumbnail and an Image as a popup - complete screwage, especially when you start assigning attributes from @params. And of course no cascade deletes, now leaving orphans in 2 tables instead of 1. Another problem here is that in the form the person should be able to upload images non-continously (i.e. - upload image in slot 4 leaving slots 1 till 3 empty). This _completely_ screws collection management in ActiveRecord, because you can (as per Ruby) do a collection assignment like Work.images[5643634] = Image.new. but the rest of the array is just filled with nils. I am in a desperate need of advice on how to deal with it. For now I just made 16 fields in my Work model which hold file names, and it works - but it''s clumsy and very ass-backwards (and not normalized). Is this such a convoluted requirement? I understand that this might not be typical for a task, but to me it feels that I don''t understand some fundamental Rails Way of implementing this stuff. I feel like working against the grain (especially evident when I try to destroy associated objects manually and start getting errors on frozen objects everywhere) There must be something that I heavily missed. -- Julian "Julik" Tarkhanov