Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #445 from die-antwort/master

Add config.base_url, use it as prefix in Uploader#url.
  • Loading branch information...
commit 7ab6ab49d5d1dd42b74c07db67e52085e9a34fb6 2 parents 392c91d + f0d31a9
@bensie bensie authored
View
3  lib/carrierwave.rb
@@ -15,7 +15,7 @@
module CarrierWave
class << self
- attr_accessor :root
+ attr_accessor :root, :base_path
def configure(&block)
CarrierWave::Uploader::Base.configure(&block)
@@ -92,6 +92,7 @@ module CarrierWave
class Railtie < Rails::Railtie
initializer "carrierwave.setup_paths" do
CarrierWave.root = Rails.root.join(Rails.public_path).to_s
+ CarrierWave.base_path = ENV['RAILS_RELATIVE_URL_ROOT']
end
initializer "carrierwave.active_record" do
View
2  lib/carrierwave/uploader/configuration.rb
@@ -8,6 +8,7 @@ module Configuration
class_attribute :_storage, :instance_writer => false
add_config :root
+ add_config :base_path
add_config :permissions
add_config :storage_engines
add_config :s3_access_policy
@@ -150,6 +151,7 @@ def reset_config
config.validate_integrity = true
config.validate_processing = true
config.root = CarrierWave.root
+ config.base_path = CarrierWave.base_path
config.enable_processing = true
config.ensure_multipart_form = true
end
View
4 lib/carrierwave/uploader/url.rb
@@ -3,6 +3,8 @@
module CarrierWave
module Uploader
module Url
+ extend ActiveSupport::Concern
+ include CarrierWave::Uploader::Configuration
##
# === Returns
@@ -13,7 +15,7 @@ def url
if file.respond_to?(:url) and not file.url.blank?
file.url
elsif current_path
- File.expand_path(current_path).gsub(File.expand_path(root), '')
+ (base_path || "") + File.expand_path(current_path).gsub(File.expand_path(root), '')
end
end
View
9 spec/uploader/url_spec.rb
@@ -51,6 +51,15 @@
@uploader.url(:thumb, :mini).should == '/uploads/tmp/20071201-1234-345-2255/thumb_mini_test.jpg'
end
+ it "should prepend the config option 'base_path', if set" do
+ @uploader_class.version(:thumb)
+ @uploader.class.configure do |config|
+ config.base_path = "/base_path"
+ end
+ @uploader.cache!(File.open(file_path('test.jpg')))
+ @uploader.url(:thumb).should == '/base_path/uploads/tmp/20071201-1234-345-2255/thumb_test.jpg'
+ end
+
it "should return file#url if available" do
@uploader.cache!(File.open(file_path('test.jpg')))
@uploader.file.stub!(:url).and_return('http://www.example.com/someurl.jpg')
Please sign in to comment.
Something went wrong with that request. Please try again.