Sha256: f3a2d30c5b395a65cc3bf7713b57ccc94f6b3e38fe0d93f397773251ee2f5381

Contents?: true

Size: 1.15 KB

Versions: 32

Compression:

Stored size: 1.15 KB

Contents

require 'rails_admin/config/fields/base'
require 'rails_admin/config/fields/types/file_upload'

module RailsAdmin
  module Config
    module Fields
      module Types
        # Field type that supports Paperclip file uploads
        class Dragonfly < RailsAdmin::Config::Fields::Types::FileUpload
          RailsAdmin::Config::Fields::Types.register(self)

          register_instance_option :image? do
            false unless value
            if abstract_model.model.new.respond_to?("#{name}_name")
              bindings[:object].send("#{name}_name").to_s.split('.').last =~ /jpg|jpeg|png|gif/i
            else
              true # Dragonfly really is image oriented
            end
          end

          register_instance_option :delete_method do
            "remove_#{name}"
          end

          register_instance_option :cache_method do
            "retained_#{name}"
          end

          register_instance_option :thumb_method do
            '100x100>'
          end

          def resource_url(thumb = false)
            return nil unless (v = value)
            thumb ? v.thumb(thumb).try(:url) : v.url
          end
        end
      end
    end
  end
end

Version data entries

32 entries across 32 versions & 2 rubygems

Version Path
rails_admin-2.3.1 lib/rails_admin/config/fields/types/dragonfly.rb
rails_admin-2.3.0 lib/rails_admin/config/fields/types/dragonfly.rb
rails_admin-2.2.1 lib/rails_admin/config/fields/types/dragonfly.rb
rails_admin-2.2.0 lib/rails_admin/config/fields/types/dragonfly.rb
rails_admin-2.1.1 lib/rails_admin/config/fields/types/dragonfly.rb
rails_admin-2.1.0 lib/rails_admin/config/fields/types/dragonfly.rb
rails_admin-2.0.2 lib/rails_admin/config/fields/types/dragonfly.rb
rails_admin-1.4.3 lib/rails_admin/config/fields/types/dragonfly.rb
rails_admin-2.0.1 lib/rails_admin/config/fields/types/dragonfly.rb
rails_admin-2.0.0 lib/rails_admin/config/fields/types/dragonfly.rb
rails_admin-2.0.0.rc lib/rails_admin/config/fields/types/dragonfly.rb
rails_admin-2.0.0.beta lib/rails_admin/config/fields/types/dragonfly.rb
rails_admin-1.4.2 lib/rails_admin/config/fields/types/dragonfly.rb
rails_admin-1.4.1 lib/rails_admin/config/fields/types/dragonfly.rb
rails_admin-1.4.0 lib/rails_admin/config/fields/types/dragonfly.rb
rails_admin-1.3.0 lib/rails_admin/config/fields/types/dragonfly.rb
rails_admin-1.2.0 lib/rails_admin/config/fields/types/dragonfly.rb
rails_admin-1.1.1 lib/rails_admin/config/fields/types/dragonfly.rb
rails_admin-1.1.0 lib/rails_admin/config/fields/types/dragonfly.rb
rails_admin-1.0.0 lib/rails_admin/config/fields/types/dragonfly.rb