【问题标题】:How to display an Active Storage image variant with Webpacker如何使用 Webpacker 显示 Active Storage 图像变体
【发布时间】:2020-05-24 11:39:39
【问题描述】:

我无法使用 Webpacker 的 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)) %>

我验证了生成的 URL 是用

<%= "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)%>

有效。我可以访问该变体,但 Webpacker 不断引发此错误:

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.

【问题讨论】:

  • 这方面有什么更新吗?我猜这是因为require.context('../images', true) in application.js;由于用户生成的内容可以存储在任何地方(如 S3、Azure 等),因此 webpack 解析这些资产一定不容易......

标签: ruby-on-rails ruby webpack rails-activestorage


【解决方案1】:

我认为你不能使用 image_pack_tag。需要使用 insted image_tag

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-24
    • 2019-01-01
    • 2018-12-08
    • 1970-01-01
    • 1970-01-01
    • 2018-11-02
    相关资源
    最近更新 更多