I have a standard polymorphic relationship, and I need to know who his parent is before I save it.
Class Picture < AR::Base belongs_to :attachable, :polymorphic => true end Class Person < AR::Base has_many :pictures, :as => :attachable end Class Vehicle < AR::Base has_many :pictures, :as => :attachable end
I upload photos through Paperclip, and I create a processor that needs to do different things for different images (for example, Person images should look like Polaroid, and images on the vehicle should have an overlay). My problem is that before the image is saved, I do not know if it is associated with a Person or a Vehicle.
I tried putting a βmarkerβ in Person and Vehicle so that I could tell them appart, but when I am in the Paperclip processor, the only thing I see is the Picture class. :( My next thought is to go up the stack to try to get parent caller, but that seems pretty smelly to me. How would you do that?
source share