mirror of
https://0xacab.org/sutty/sutty
synced 2024-11-16 15:41:42 +00:00
asignar archivos subidos desde el editor al sitio
This commit is contained in:
parent
c13c021fe9
commit
211fb308e3
1 changed files with 33 additions and 0 deletions
33
app/controllers/active_storage/disk_controller_decorator.rb
Normal file
33
app/controllers/active_storage/disk_controller_decorator.rb
Normal file
|
@ -0,0 +1,33 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module ActiveStorage
|
||||
# Modificar {DiskController} para poder asociar el blob a un sitio
|
||||
module DiskControllerDecorator
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
included do
|
||||
# Asociar el archivo subido al sitio correspondiente. Cada sitio
|
||||
# tiene su propio servicio de subida de archivos.
|
||||
def update
|
||||
if (token = decode_verified_token)
|
||||
if acceptable_content?(token)
|
||||
named_disk_service(token[:service_name]).upload token[:key], request.body, checksum: token[:checksum]
|
||||
|
||||
blob = ActiveStorage::Blob.find_by_key token[:key]
|
||||
site = Site.find_by_name token[:service_name]
|
||||
|
||||
site.static_files.attach(blob)
|
||||
else
|
||||
head :unprocessable_entity
|
||||
end
|
||||
else
|
||||
head :not_found
|
||||
end
|
||||
rescue ActiveStorage::IntegrityError
|
||||
head :unprocessable_entity
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
ActiveStorage::DiskController.include ActiveStorage::DiskControllerDecorator
|
Loading…
Reference in a new issue