I have a problem with including images in my views using Ruby on Rails Webpacker. When i try to insert image in my view using html img tag and asset_pack_path i got an error. My
Place your images in
app/javascripts/images
Put following code in application.js
At TOP of the file.
// top of packs/application.js
const importAll = (r) => r.keys().map(r)
importAll(require.context('../images', false, /\.(png|jpe?g|svg)$/));
This will load all images from images folder and then it should be available in manifest for you to pick up using
asset_pack_path
In your erb
files, use like <%= asset_pack_path 'media/images/image_name.png' %>
-- Read this for more details https://github.com/rails/webpacker/issues/1839