1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Move controllers to default engine location for auto loading

This commit is contained in:
David Heinemeier Hansson 2017-07-20 17:34:13 -05:00
parent 1a9026b485
commit 1c85eecee0
4 changed files with 23 additions and 14 deletions

View file

@ -3,6 +3,7 @@ require "bundler/gem_tasks"
require "rake/testtask"
Rake::TestTask.new do |test|
test.libs << "app/controllers"
test.libs << "test"
test.test_files = FileList["test/**/*_test.rb"]
test.warning = false

View file

@ -0,0 +1,22 @@
class ActiveStorage::VariantsController < ActionController::Base
def show
if blob_key = decode_verified_blob_key
redirect_to processed_variant_for(blob_key).url(disposition: disposition_param)
else
head :not_found
end
end
private
def decode_verified_blob_key
ActiveStorage::VerifiedKeyWithExpiration.decode(params[:encoded_blob_key])
end
def processed_variant_for(blob_key)
ActiveStorage::Variant.find_or_process_by!(blob_key: blob_key, encoded_variant_key: params[:encoded_variant_key])
end
def disposition_param
params[:disposition].presence_in(%w( inline attachment )) || 'inline'
end
end

View file

@ -1,14 +0,0 @@
require "action_controller"
require "active_storage/blob"
class ActiveStorage::DirectUploadsController < ActionController::Base
def create
blob = ActiveStorage::Blob.create_before_direct_upload!(blob_args)
render json: { url: blob.url_for_direct_upload, sgid: blob.to_sgid.to_param }
end
private
def blob_args
params.require(:blob).permit(:filename, :byte_size, :checksum, :content_type, :metadata).to_h.symbolize_keys
end
end