acts_as_having_image.rb 559 Bytes
module ActsAsHavingImage

  module ClassMethods
    def acts_as_having_image
      belongs_to :image
      scope :with_image, :conditions => [ "#{table_name}.image_id IS NOT NULL" ]
      scope :without_image, :conditions => [ "#{table_name}.image_id IS NULL" ]
      self.send(:include, ActsAsHavingImage)
    end
  end

  def image_builder=(img)
    if image && image.id == img[:id]
      image.attributes = img
    else
      build_image(img)
    end unless img[:uploaded_data].blank?
  end

end

ActiveRecord::Base.extend(ActsAsHavingImage::ClassMethods)