Module: Panda::Core::ActiveStorageHelper
- Defined in:
- app/helpers/panda/core/active_storage_helper.rb
Instance Method Summary collapse
-
#variant_representation_url(variant) ⇒ String?
Generates a URL for an ActiveStorage variant, compatible with both Rails 7.x and 8.1+.
Instance Method Details
#variant_representation_url(variant) ⇒ String?
Generates a URL for an ActiveStorage variant, compatible with both Rails 7.x and 8.1+.
In Rails 8.1+, both url_for(variant) and image_tag(variant) break because VariantWithRecord no longer implements to_model. This helper constructs the representation proxy path directly from the blob and variation, avoiding all polymorphic routing that relies on to_model.
15 16 17 18 19 20 21 |
# File 'app/helpers/panda/core/active_storage_helper.rb', line 15 def variant_representation_url(variant) blob = variant.blob "/rails/active_storage/representations/proxy/#{blob.signed_id}/#{variant.variation.key}/#{blob.filename}" rescue => e Rails.logger.warn "[Panda] Failed to generate variant URL (#{e.class}): #{e.}" nil end |