Sha256: 139b5e0c0986fceb8d0354586737cafb780fefcb6d4188a39eab9d91cd45a070

Contents?: true

Size: 1.22 KB

Versions: 12

Compression:

Stored size: 1.22 KB

Contents

module RailsAdminSettings
  module Uploads
    autoload :CarrierWave, "rails_admin_settings/storage/carrierwave"

    def self.included(base)
      # carrierwave
      if base.respond_to?(:mount_uploader)
        # puts "[rails_admin_settings] CarrierWave detected"
        # base.field(:file, type: String)
        base.mount_uploader(:file, RailsAdminSettings::Uploads::CarrierWave)
        Settings.file_uploads_supported = true
        Settings.file_uploads_engine = :carrierwave
      # paperclip
      elsif Mongoid.const_defined?('Paperclip')
        base.send(:include, Mongoid::Paperclip)
        # puts "[rails_admin_settings] PaperClip detected"
        base.field(:file, type: String)
        if defined?(Rails)
          base.has_mongoid_attached_file(:file)
        else
          base.has_mongoid_attached_file(:file, path: "#{File.dirname(__FILE__)}/../../uploads/:filename", url: '/uploads/:filename')
        end
        base.send(:attr_accessor, :delete_file)
        base.before_validation { self.file.clear if self.delete_file == '1' }

        Settings.file_uploads_supported = true
        Settings.file_uploads_engine = :paperclip
      else
        # puts "[rails_admin_settings] Uploads disabled"
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
rails_admin_settings-0.7.2 lib/rails_admin_settings/uploads.rb
rails_admin_settings-0.7.1 lib/rails_admin_settings/uploads.rb
rails_admin_settings-0.7.0 lib/rails_admin_settings/uploads.rb
rails_admin_settings-0.6.8 lib/rails_admin_settings/uploads.rb
rails_admin_settings-0.6.7 lib/rails_admin_settings/uploads.rb
rails_admin_settings-0.6.5 lib/rails_admin_settings/uploads.rb
rails_admin_settings-0.6.4 lib/rails_admin_settings/uploads.rb
rails_admin_settings-0.6.3 lib/rails_admin_settings/uploads.rb
rails_admin_settings-0.6.2 lib/rails_admin_settings/uploads.rb
rails_admin_settings-0.6.1 lib/rails_admin_settings/uploads.rb
rails_admin_settings-0.6.0 lib/rails_admin_settings/uploads.rb
rails_admin_settings-0.5.5 lib/rails_admin_settings/uploads.rb