Sha256: 31ccaf56a7257dee3314f30a0069a7e304a2a763cf0fde341af26222b7d82775

Contents?: true

Size: 977 Bytes

Versions: 15

Compression:

Stored size: 977 Bytes

Contents

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

module RailsAdmin
  module Config
    module Fields
      module Types
        class Carrierwave < RailsAdmin::Config::Fields::Types::FileUpload
          RailsAdmin::Config::Fields::Types.register(self)

          register_instance_option :thumb_method do
            @thumb_method ||= ((versions = bindings[:object].send(name).versions.keys).find{|k| k.in?([:thumb, :thumbnail, 'thumb', 'thumbnail'])} || versions.first.to_s)
          end

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

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

          def resource_url(thumb = false)
            return nil unless (uploader = bindings[:object].send(name)).present?
            thumb.present? ? uploader.send(thumb).url : uploader.url
          end
        end
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 2 rubygems

Version Path
rails_admin-0.6.0 lib/rails_admin/config/fields/types/carrierwave.rb
rails_admin-0.5.0 lib/rails_admin/config/fields/types/carrierwave.rb
rails_admin-0.4.9 lib/rails_admin/config/fields/types/carrierwave.rb
rails_admin-0.4.8 lib/rails_admin/config/fields/types/carrierwave.rb
rails_admin-0.4.7 lib/rails_admin/config/fields/types/carrierwave.rb
rails_admin-0.4.6 lib/rails_admin/config/fields/types/carrierwave.rb
rails_admin-0.4.5 lib/rails_admin/config/fields/types/carrierwave.rb
rails_admin-0.4.4 lib/rails_admin/config/fields/types/carrierwave.rb
rails_admin-lbgraham-0.4.2 lib/rails_admin/config/fields/types/carrierwave.rb
rails_admin-0.4.3 lib/rails_admin/config/fields/types/carrierwave.rb
rails_admin-0.4.2 lib/rails_admin/config/fields/types/carrierwave.rb
rails_admin-0.4.1 lib/rails_admin/config/fields/types/carrierwave.rb
rails_admin-0.4.0 lib/rails_admin/config/fields/types/carrierwave.rb
rails_admin-0.3.0 lib/rails_admin/config/fields/types/carrierwave.rb
rails_admin-0.2.0 lib/rails_admin/config/fields/types/carrierwave.rb