Sha256: 54b51853edd15770f79218d11e0de81ac820798ad59effb93d5e87b03c16d217
Contents?: true
Size: 1.06 KB
Versions: 1
Compression:
Stored size: 1.06 KB
Contents
module Technoweenie # :nodoc: module AttachmentFu # :nodoc: module Backends # Methods for DB backed attachments class DbFileBackend < BackendDelegator def self.included_in_base(base) Object.const_set(:DbFile, Class.new(ActiveRecord::Base)) unless Object.const_defined?(:DbFile) base.belongs_to :db_file, :class_name => '::DbFile', :foreign_key => 'db_file_id' end def rename_file ; end # Gets the current data from the database def current_data db_file && db_file.data end # Destroys the file. Called in the after_destroy callback def destroy_file db_file.destroy if db_file end # Saves the data to the DbFile model def save_to_storage if save_attachment? (db_file || build_db_file).data = temp_data db_file.save! @obj.db_file_id = db_file.id @obj.class.where(id: @obj.id).update_all db_file_id: db_file.id end true end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
attachment_zen-1.0.1 | lib/technoweenie/attachment_fu/backends/db_file_backend.rb |