diff options
author | George Claghorn <george.claghorn@gmail.com> | 2018-09-14 13:53:16 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-09-14 13:53:16 -0400 |
commit | 65bf046fd1c05405591b940e3b3cd718ca1edba1 (patch) | |
tree | 7fe01750df956b3262f3ac5164f4f9e13210d650 | |
parent | 9cafaadc0cce68143bb7390f9b147ed23da38737 (diff) | |
parent | 7dd9916c0d5e5d149bdde8cbeec42ca49cf3f6ca (diff) | |
download | rails-65bf046fd1c05405591b940e3b3cd718ca1edba1.tar.gz rails-65bf046fd1c05405591b940e3b3cd718ca1edba1.tar.bz2 rails-65bf046fd1c05405591b940e3b3cd718ca1edba1.zip |
Merge pull request #33883 from cbisnett/active_storage_route_prefix_configuration
Configure Active Storage route prefix
-rw-r--r-- | activestorage/CHANGELOG.md | 4 | ||||
-rw-r--r-- | activestorage/config/routes.rb | 25 | ||||
-rw-r--r-- | activestorage/lib/active_storage.rb | 1 | ||||
-rw-r--r-- | activestorage/lib/active_storage/engine.rb | 1 | ||||
-rw-r--r-- | guides/source/configuring.md | 8 |
5 files changed, 27 insertions, 12 deletions
diff --git a/activestorage/CHANGELOG.md b/activestorage/CHANGELOG.md index 92e300a440..f4e2826dc6 100644 --- a/activestorage/CHANGELOG.md +++ b/activestorage/CHANGELOG.md @@ -1,3 +1,7 @@ +* Add `ActiveStorage.routes_prefix` for configuring generated routes. + + *Chris Bisnett* + * `ActiveStorage::Service::AzureStorageService` only handles specifically relevant types of `Azure::Core::Http::HTTPError`. It previously obscured other types of `HTTPError`, which is the azure-storage gem’s catch-all diff --git a/activestorage/config/routes.rb b/activestorage/config/routes.rb index 20d19f334a..3af7361cff 100644 --- a/activestorage/config/routes.rb +++ b/activestorage/config/routes.rb @@ -1,17 +1,15 @@ # frozen_string_literal: true Rails.application.routes.draw do - get "/rails/active_storage/blobs/:signed_id/*filename" => "active_storage/blobs#show", as: :rails_service_blob - - direct :rails_blob do |blob, options| - route_for(:rails_service_blob, blob.signed_id, blob.filename, options) - end - - resolve("ActiveStorage::Blob") { |blob, options| route_for(:rails_blob, blob, options) } - resolve("ActiveStorage::Attachment") { |attachment, options| route_for(:rails_blob, attachment.blob, options) } + scope ActiveStorage.routes_prefix do + get "/blobs/:signed_id/*filename" => "active_storage/blobs#show", as: :rails_service_blob + get "/representations/:signed_blob_id/:variation_key/*filename" => "active_storage/representations#show", as: :rails_blob_representation - get "/rails/active_storage/representations/:signed_blob_id/:variation_key/*filename" => "active_storage/representations#show", as: :rails_blob_representation + get "/disk/:encoded_key/*filename" => "active_storage/disk#show", as: :rails_disk_service + put "/disk/:encoded_token" => "active_storage/disk#update", as: :update_rails_disk_service + post "/direct_uploads" => "active_storage/direct_uploads#create", as: :rails_direct_uploads + end direct :rails_representation do |representation, options| signed_blob_id = representation.blob.signed_id @@ -25,7 +23,10 @@ Rails.application.routes.draw do resolve("ActiveStorage::Preview") { |preview, options| route_for(:rails_representation, preview, options) } - get "/rails/active_storage/disk/:encoded_key/*filename" => "active_storage/disk#show", as: :rails_disk_service - put "/rails/active_storage/disk/:encoded_token" => "active_storage/disk#update", as: :update_rails_disk_service - post "/rails/active_storage/direct_uploads" => "active_storage/direct_uploads#create", as: :rails_direct_uploads + direct :rails_blob do |blob, options| + route_for(:rails_service_blob, blob.signed_id, blob.filename, options) + end + + resolve("ActiveStorage::Blob") { |blob, options| route_for(:rails_blob, blob, options) } + resolve("ActiveStorage::Attachment") { |attachment, options| route_for(:rails_blob, attachment.blob, options) } end diff --git a/activestorage/lib/active_storage.rb b/activestorage/lib/active_storage.rb index d3e3a2f49b..a94ef626f2 100644 --- a/activestorage/lib/active_storage.rb +++ b/activestorage/lib/active_storage.rb @@ -50,6 +50,7 @@ module ActiveStorage mattr_accessor :variable_content_types, default: [] mattr_accessor :content_types_to_serve_as_binary, default: [] mattr_accessor :service_urls_expire_in, default: 5.minutes + mattr_accessor :routes_prefix, default: "/rails/active_storage" module Transformers extend ActiveSupport::Autoload diff --git a/activestorage/lib/active_storage/engine.rb b/activestorage/lib/active_storage/engine.rb index 9d6a27eabe..7eb93b5e16 100644 --- a/activestorage/lib/active_storage/engine.rb +++ b/activestorage/lib/active_storage/engine.rb @@ -51,6 +51,7 @@ module ActiveStorage ActiveStorage.previewers = app.config.active_storage.previewers || [] 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.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 || [] diff --git a/guides/source/configuring.md b/guides/source/configuring.md index 0ff6f48c14..e372b3a816 100644 --- a/guides/source/configuring.md +++ b/guides/source/configuring.md @@ -832,6 +832,14 @@ text/javascript image/svg+xml application/postscript application/x-shockwave-fla The default is 5 minutes. +* `config.active_storage.routes_prefix` can be used to set the route prefix for the routes served by Active Storage. Accepts a string that will be prepended to the generated routes. + + ```ruby + config.active_storage.routes_prefix = '/files' + ``` + + The default is `/rails/active_storage` + ### Configuring a Database Just about every Rails application will interact with a database. You can connect to the database by setting an environment variable `ENV['DATABASE_URL']` or by using a configuration file called `config/database.yml`. |