Class: RailsAdminImageManager::File

Inherits:
ApplicationRecord show all
Defined in:
app/models/rails_admin_image_manager/file.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#srcObject

Returns the value of attribute src.



16
17
18
# File 'app/models/rails_admin_image_manager/file.rb', line 16

def src
  @src
end

#src_for_wysiwygObject

Returns the value of attribute src_for_wysiwyg.



17
18
19
# File 'app/models/rails_admin_image_manager/file.rb', line 17

def src_for_wysiwyg
  @src_for_wysiwyg
end

Instance Method Details

#decode_base64_imageObject



55
56
57
58
59
60
61
# File 'app/models/rails_admin_image_manager/file.rb', line 55

def decode_base64_image
  if src.present? && src.include?('data:image')
    new_image = Paperclip.io_adapters.for(src)
    new_image.original_filename = image_file_name
    self.image = new_image
  end
end

#delete_image_folderObject



63
64
65
# File 'app/models/rails_admin_image_manager/file.rb', line 63

def delete_image_folder
  FileUtils.rm_rf(::File.dirname(image.path(:original))+'/../') if (self.changes.key?('image_file_name') && self.changes.key?('image_file_size'))
end

#destroyObject

To avoid the 500 error when the foreign key constraint fails



47
48
49
50
51
52
53
# File 'app/models/rails_admin_image_manager/file.rb', line 47

def destroy
  begin
    super
  rescue
    return false
  end
end

#tags_listObject



77
78
79
# File 'app/models/rails_admin_image_manager/file.rb', line 77

def tags_list
  tags.collect { |t| t.name }
end