1 module Technoweenie # :nodoc:
2 module AttachmentFu # :nodoc:
4 # Methods for DB backed attachments
6 def self.included(base) #:nodoc:
7 Object.const_set(:DbFile, Class.new(ActiveRecord::Base)) unless Object.const_defined?(:DbFile)
8 base.belongs_to :db_file, :class_name => '::DbFile', :foreign_key => 'db_file_id'
11 # Creates a temp file with the current db data.
13 write_to_temp_file current_data
16 # Gets the current data from the database
22 # Destroys the file. Called in the after_destroy callback
24 db_file.destroy if db_file
27 # Saves the data to the DbFile model
30 (db_file || build_db_file).data = temp_data
32 self.class.update_all ['db_file_id = ?', self.db_file_id = db_file.id], ['id = ?', id]