Search code examples
ruby-on-railsrubywebpackrails-activestorage

How to display an Active Storage image variant with Webpacker


I can't display an image using Webpacker's image_pack_tag:

<%= image_pack_tag("http://localhost:3000" + Rails.application.routes.url_helpers.rails_representation_url(current_user.profil_picture.variant(resize_to_limit: [50, 50]).processed, only_path: true)) %>

I verified that the URL generated with

<%= "http://localhost:3000" + Rails.application.routes.url_helpers.rails_representation_url(current_user.profil_picture.variant(resize_to_limit: [50, 50]).processed, only_path: true)%>

works. I can access the variant but Webpacker keep raising this error:

Webpacker can't find http://localhost:3000/rails/active_storage/representations/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaHBCZz09IiwiZXhwIjpudWxsLCJwdXIiOiJibG9iX2lkIn19--9959728effdbb975d843d4f452319f6363c4ceac/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaDdCam9VY21WemFYcGxYM1J2WDJ4cGJXbDBXd2RwTjJrMyIsImV4cCI6bnVsbCwicHVyIjoidmFyaWF0aW9uIn19--120e67a3ba1bc8800d715fbf351aea75a4993405/profile.jpg in /mnt/c/Users/lethu/Documents/apps/safe_date/public/packs/manifest.json.

Solution

  • i think you can't use image_pack_tag. Need to use insted image_tag