Michael Daines
2005-May-02 22:37 UTC
(fixed) Mixing in functionality in ActiveRecord? (was Re: has_many and belongs_to associations...)
I found out a way to fix this -- I use the same pattern as the search
generator.
I require ''has_attachments'', and then put a line in my model
that calls
this ''has_attachments'' method:
class ActiveRecord::Base
def self.has_attachments
class_eval <<-EOV
include HasAttachments
has_many :attachments, :foreign_key =>
''record_id'',
:conditions => "record_table =
''#{self.table_name}''"
EOV
end
end
...then a module follows, with my (not yet fully tested, and specific
to my implementation) attachment functions. Now any of my models may
have files attached to them.