diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2017-07-20 17:33:31 -0500 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2017-07-20 17:33:31 -0500 |
commit | 1a9026b485b9b1da0f34c526d4c901406074c508 (patch) | |
tree | 8f3b8eae6786a35fc934a04ed9234ec95b90eee3 | |
parent | dda013050fe559e2e9432ae836c1239eac48fbce (diff) | |
download | rails-1a9026b485b9b1da0f34c526d4c901406074c508.tar.gz rails-1a9026b485b9b1da0f34c526d4c901406074c508.tar.bz2 rails-1a9026b485b9b1da0f34c526d4c901406074c508.zip |
Extract routes.rb to engine location for auto configuration
-rw-r--r-- | config/routes.rb | 13 | ||||
-rw-r--r-- | lib/active_storage/engine.rb | 11 | ||||
-rw-r--r-- | lib/active_storage/routes.rb | 3 | ||||
-rw-r--r-- | test/test_helper.rb | 11 |
4 files changed, 13 insertions, 25 deletions
diff --git a/config/routes.rb b/config/routes.rb new file mode 100644 index 0000000000..9057eadc8a --- /dev/null +++ b/config/routes.rb @@ -0,0 +1,13 @@ +Rails.application.routes.draw do + get "/rails/active_storage/disk/:encoded_key/*filename" => "active_storage/disk#show", as: :rails_disk_blob + get "/rails/active_storage/variants/:encoded_blob_key/:encoded_variant_key/*filename" => "active_storage/variants#show", as: :rails_blob_variant + post "/rails/active_storage/direct_uploads" => "active_storage/direct_uploads#create", as: :rails_direct_uploads + + resolve 'ActiveStorage::Variant' do |variant| + encoded_blob_key = ActiveStorage::VerifiedKeyWithExpiration.encode(variant.blob.key) + encoded_variant_key = ActiveStorage::Variant.encode_key(variant.variation) + filename = variant.blob.filename + + route_for(:rails_blob_variant, encoded_blob_key, encoded_variant_key, filename) + end +end diff --git a/lib/active_storage/engine.rb b/lib/active_storage/engine.rb index 8918b179e0..b04925a9fd 100644 --- a/lib/active_storage/engine.rb +++ b/lib/active_storage/engine.rb @@ -14,17 +14,6 @@ module ActiveStorage end end - initializer "active_storage.routes" do - require "active_storage/disk_controller" - require "active_storage/direct_uploads_controller" - - config.after_initialize do |app| - app.routes.prepend do - eval(File.read(File.expand_path("../routes.rb", __FILE__))) - end - end - end - initializer "active_storage.attached" do require "active_storage/attached" diff --git a/lib/active_storage/routes.rb b/lib/active_storage/routes.rb deleted file mode 100644 index fade234ad3..0000000000 --- a/lib/active_storage/routes.rb +++ /dev/null @@ -1,3 +0,0 @@ -get "/rails/active_storage/disk/:encoded_key/*filename" => "active_storage/disk#show", as: :rails_disk_blob -get "/rails/active_storage/variants/:encoded_key/:encoded_transformation/*filename" => "active_storage/controllers/variants#show", as: :rails_blob_variant -post "/rails/active_storage/direct_uploads" => "active_storage/direct_uploads#create", as: :rails_direct_uploads diff --git a/test/test_helper.rb b/test/test_helper.rb index 878ce8391c..6081fc1bcf 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -34,17 +34,6 @@ class ActiveSupport::TestCase end end -require "action_controller" -require "action_controller/test_case" - -class ActionController::TestCase - Routes = ActionDispatch::Routing::RouteSet.new.tap do |routes| - routes.draw do - eval(File.read(File.expand_path("../../lib/active_storage/routes.rb", __FILE__))) - end - end -end - require "active_storage/attached" ActiveRecord::Base.send :extend, ActiveStorage::Attached::Macros |