Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions app/decorators/decidim/attachment_patch.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# frozen_string_literal: true

# Patch pour corriger la méthode file_type dans Decidim::Attachment
# afin d'afficher le bon type MIME sans les query params AWS S3.

# app/decorators/decidim/attachment_patch.rb

module Decidim
module AttachmentPatch
end
end

Rails.logger.info "Patch chargé : Decidim::Attachment#file_type"

Decidim::Attachment.class_eval do
def file_type
return file.blob.content_type.split("/").last.upcase if file.attached? && file.respond_to?(:blob)

return content_type.split("/").last.upcase if respond_to?(:content_type) && content_type.present?

"UNKNOWN"
rescue StandardError => e
Rails.logger.warn("[Attachment#file_type patch] #{e.class}: #{e.message}")
"UNKNOWN"
end
end
13 changes: 13 additions & 0 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ class Application < Rails::Application
# Initialize configuration defaults for originally generated Rails version.
config.load_defaults 6.1

# Empêche Zeitwerk d'autoload le dossier decorators
config.autoload_paths -= Rails.root.glob("app/decorators")
config.eager_load_paths -= Rails.root.glob("app/decorators")

# Configuration for the application, engines, and railties goes here.
#
# These settings can be overridden in specific environments using the files
Expand All @@ -33,5 +37,14 @@ class Application < Rails::Application
require "extends/controllers/decidim/devise/omniauth_registrations_controller_extends"
require "extends/controllers/decidim/errors_controller_extends"
end
# --- FORCE LE CHARGEMENT DES DÉCORATEURS ---
# Chargement après initialisation complète de Rails
config.after_initialize do
decorators_path = Rails.root.join("app/decorators/**/*.rb")
Dir[decorators_path].each do |decorator|
Rails.logger.info "💡 Chargement manuel du décorateur : #{File.basename(decorator)}"
require decorator
end
end
end
end
File renamed without changes.