aboutsummaryrefslogtreecommitdiffstats
path: root/activestorage
diff options
context:
space:
mode:
authorGannon McGibbon <gannon.mcgibbon@gmail.com>2019-07-12 15:30:28 -0400
committerGannon McGibbon <gannon.mcgibbon@gmail.com>2019-07-22 12:35:04 -0400
commit3cf65bcb8ee3c27204dee5cac003a749973240f9 (patch)
treeb3d5537d6fe9e84ece34ef1bf4cb4e3d70226fc7 /activestorage
parent3b36d75c8fef2e8d3bc9db87486729d4e8229840 (diff)
downloadrails-3cf65bcb8ee3c27204dee5cac003a749973240f9.tar.gz
rails-3cf65bcb8ee3c27204dee5cac003a749973240f9.tar.bz2
rails-3cf65bcb8ee3c27204dee5cac003a749973240f9.zip
Make Active Storage routes optional
Add configuration option to turn off drawing of Active Storage routes.
Diffstat (limited to 'activestorage')
-rw-r--r--activestorage/CHANGELOG.md4
-rw-r--r--activestorage/config/routes.rb2
-rw-r--r--activestorage/lib/active_storage.rb1
-rw-r--r--activestorage/lib/active_storage/engine.rb1
4 files changed, 7 insertions, 1 deletions
diff --git a/activestorage/CHANGELOG.md b/activestorage/CHANGELOG.md
index fdb0f143f4..1475a7a786 100644
--- a/activestorage/CHANGELOG.md
+++ b/activestorage/CHANGELOG.md
@@ -1,3 +1,7 @@
+* Add `config.active_storage.draw_routes` to disable Active Storage routes.
+
+ *Gannon McGibbon*
+
* Image analysis is skipped if ImageMagick returns an error.
`ActiveStorage::Analyzer::ImageAnalyzer#metadata` would previously raise a
diff --git a/activestorage/config/routes.rb b/activestorage/config/routes.rb
index 3af7361cff..bde53e72f3 100644
--- a/activestorage/config/routes.rb
+++ b/activestorage/config/routes.rb
@@ -29,4 +29,4 @@ Rails.application.routes.draw do
resolve("ActiveStorage::Blob") { |blob, options| route_for(:rails_blob, blob, options) }
resolve("ActiveStorage::Attachment") { |attachment, options| route_for(:rails_blob, attachment.blob, options) }
-end
+end if ActiveStorage.draw_routes
diff --git a/activestorage/lib/active_storage.rb b/activestorage/lib/active_storage.rb
index 75eb63f0b4..c35a9920d6 100644
--- a/activestorage/lib/active_storage.rb
+++ b/activestorage/lib/active_storage.rb
@@ -60,6 +60,7 @@ module ActiveStorage
mattr_accessor :service_urls_expire_in, default: 5.minutes
mattr_accessor :routes_prefix, default: "/rails/active_storage"
+ mattr_accessor :draw_routes, default: true
mattr_accessor :replace_on_assign_to_many, default: false
diff --git a/activestorage/lib/active_storage/engine.rb b/activestorage/lib/active_storage/engine.rb
index e88e7fa14e..9d9cd02d12 100644
--- a/activestorage/lib/active_storage/engine.rb
+++ b/activestorage/lib/active_storage/engine.rb
@@ -73,6 +73,7 @@ module ActiveStorage
ActiveStorage.analyzers = app.config.active_storage.analyzers || []
ActiveStorage.paths = app.config.active_storage.paths || {}
ActiveStorage.routes_prefix = app.config.active_storage.routes_prefix || "/rails/active_storage"
+ ActiveStorage.draw_routes = app.config.active_storage.draw_routes != false
ActiveStorage.variable_content_types = app.config.active_storage.variable_content_types || []
ActiveStorage.content_types_to_serve_as_binary = app.config.active_storage.content_types_to_serve_as_binary || []