【发布时间】:2020-02-08 01:56:50
【问题描述】:
使用 webpacker 处理新的 Rails 6 应用程序。图像存储在/app/frontend/images。
//added to /app/frontend/application.js
const images = require.context('../images', true)
const imagePath = (name) => images(name, true)
Webpacker 配置:
/config/webpacker.yml contains:
default: &default
source_path: app/frontend
source_entry_path: packs
public_root_path: public
public_output_path: packs
cache_path: tmp/cache/webpacker
check_yarn_integrity: false
webpack_compile_output: true
我的问题:image_pack_tag 错误地将 assets/ 添加到图像路径。
<%= image_pack_tag 'media/images/AdminLTELogo.png', alt: 'AdminLTE Logo', class: "brand-image img-circle elevation-3", style: "opacity: .8" %>
渲染...
<img alt="AdminLTE Logo" class="brand-image img-circle elevation-3" style="opacity: .8" src="/assets/%2Fpacks%2Fmedia%2Fimages%2FAdminLTELogo-28f7e31d41f353b3aaff1236c7108479.png">
从路径中删除assets/ 将成功渲染图像。
有什么想法可以将assets/ 添加到图像路径中吗?
【问题讨论】:
标签: image tags pack ruby-on-rails-6 webpacker