Sha256: c11d366746c6651d8ef61f7664bd69fa4441258876a045d96fd50898b6954750

Contents?: true

Size: 1.3 KB

Versions: 63

Compression:

Stored size: 1.3 KB

Contents

class Lalala::Uploaders::File < CarrierWave::Uploader::Base

  def store_dir
    if Rails.env.production? or Rails.env.staging?
      "#{model.class.to_s.underscore}/#{model.id}"
    else
      "uploads/#{model.class.to_s.underscore}/#{model.id}"
    end
  end

  def url(*)
    super_url = super
    if Rails.env.production? or Rails.env.staging?
      if super_url
        if super_url.starts_with?('/storage/assets')
          super_url
        else
          AssetURL.new(File.join("/storage/assets", super_url))
        end
      else
        super_url
      end
    else
      super_url
    end
  end

  # This class circumvents the Sprockets asset path rewriting
  # by pretending that it is a full URL.
  #
  # @see
  #   https://mrhenry.basecamphq.com/projects/10235776-hetpaleis/todo_items/164031435/comments (internal)
  #   http://apidock.com/rails/ActionView/Helpers/AssetTagHelper/image_tag
  #   http://apidock.com/rails/v3.2.13/ActionView/Helpers/AssetTagHelper/path_to_image
  #   http://apidock.com/rails/ActionView/Helpers/AssetTagHelper/image_path
  #   http://apidock.com/rails/ActionView/AssetPaths/compute_public_path
  #   http://apidock.com/rails/v3.2.13/ActionView/AssetPaths/is_uri%3F
  class AssetURL < String

    def to_s
      self
    end

    def =~(pattern)
      return true
    end

  end

end

Version data entries

63 entries across 63 versions & 1 rubygems

Version Path
lalala-4.0.0.dev.416 lib/lalala/uploaders/file.rb
lalala-4.0.0.dev.407 lib/lalala/uploaders/file.rb
lalala-4.0.0.dev.396 lib/lalala/uploaders/file.rb
lalala-4.0.0.dev.395 lib/lalala/uploaders/file.rb
lalala-4.0.0.dev.393 lib/lalala/uploaders/file.rb
lalala-4.0.0.dev.388 lib/lalala/uploaders/file.rb
lalala-4.0.0.dev.385 lib/lalala/uploaders/file.rb
lalala-4.0.0.dev.382 lib/lalala/uploaders/file.rb
lalala-4.0.0.dev.374 lib/lalala/uploaders/file.rb
lalala-4.0.0.dev.372 lib/lalala/uploaders/file.rb
lalala-4.0.0.dev.368 lib/lalala/uploaders/file.rb
lalala-4.0.0.dev.366 lib/lalala/uploaders/file.rb
lalala-4.0.0.dev.357 lib/lalala/uploaders/file.rb
lalala-4.0.0.dev.354 lib/lalala/uploaders/file.rb
lalala-4.0.0.dev.351 lib/lalala/uploaders/file.rb
lalala-4.0.0.dev.350 lib/lalala/uploaders/file.rb
lalala-4.0.0.dev.349 lib/lalala/uploaders/file.rb
lalala-4.0.0.dev.344 lib/lalala/uploaders/file.rb
lalala-4.0.0.dev.343 lib/lalala/uploaders/file.rb
lalala-4.0.0.dev.339 lib/lalala/uploaders/file.rb