Topic: Polymorphism

Hello everyone,

I m using polymorphism in my application and I would like to make it clean, I have different type of files such as "source_file", "target_file", "generated_file" they are all using the rails polymorphism mechanism that make them "shared_files". So what i did is redifing the "save" method so when one of this kind of file is added into the database, the coressponding shared_file is also created like this :

def save(*args)
    super
    sharedfile = SharedFile.new
    sharedfile.file=self
    sharedfile.save
end

it works fine, but the thing is i redefined this method in each of my classes... so what i would like to have is something like :
class File < ActiveRecord::Base

  def save(*args)
    super
    sharedfile = SharedFile.new
    sharedfile.file=self
    sharedfile.save
  end

end

class SourceFile < File

  has_one :shared_file, :as => :file
 
  has_attachment :storage => :file_system
  validates_as_attachment
 
end


But when I do that i get an error yelling at me that : "undefined method `has_attachment' for SourceFile:Class"

So I actually have a bunch of question here :
1) Is there a way to solve that ?
2) Is that clean ?
3) Could I actually make an heritage between SharedFile(instead of using a new class File) and SourceFile 

Thanks for your help