aboutsummaryrefslogtreecommitdiffstats
path: root/activestorage/app
diff options
context:
space:
mode:
authorAndrew White <andrew.white@unboxed.co>2018-03-26 14:36:39 +0100
committerAndrew White <andrew.white@unboxed.co>2018-04-06 20:07:52 +0100
commit9436c22e2aa9419f275186967a1b863bc3d01ecb (patch)
tree3a833e8e5f773d0f6668b44d15bceb644db932a3 /activestorage/app
parent03bd370c02a8fa83ab6dd01bdd99fe342c523b81 (diff)
downloadrails-9436c22e2aa9419f275186967a1b863bc3d01ecb.tar.gz
rails-9436c22e2aa9419f275186967a1b863bc3d01ecb.tar.bz2
rails-9436c22e2aa9419f275186967a1b863bc3d01ecb.zip
Use a current model to provide the host for service urls
Trying to pass the current request down to the service so that it can create full urls instead of paths makes the API messy so use a model based on ActiveSupport::CurrentAttributes to provide the current host to services that need it (primarily the disk service).
Diffstat (limited to 'activestorage/app')
-rw-r--r--activestorage/app/controllers/active_storage/base_controller.rb4
-rw-r--r--activestorage/app/models/active_storage/current.rb5
2 files changed, 9 insertions, 0 deletions
diff --git a/activestorage/app/controllers/active_storage/base_controller.rb b/activestorage/app/controllers/active_storage/base_controller.rb
index ba825883b9..59312ac8df 100644
--- a/activestorage/app/controllers/active_storage/base_controller.rb
+++ b/activestorage/app/controllers/active_storage/base_controller.rb
@@ -3,4 +3,8 @@
# The base controller for all ActiveStorage controllers.
class ActiveStorage::BaseController < ActionController::Base
protect_from_forgery with: :exception
+
+ before_action do
+ ActiveStorage::Current.host = request.base_url
+ end
end
diff --git a/activestorage/app/models/active_storage/current.rb b/activestorage/app/models/active_storage/current.rb
new file mode 100644
index 0000000000..7e431d8462
--- /dev/null
+++ b/activestorage/app/models/active_storage/current.rb
@@ -0,0 +1,5 @@
+# frozen_string_literal: true
+
+class ActiveStorage::Current < ActiveSupport::CurrentAttributes #:nodoc:
+ attribute :host
+end