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
It looks like the path is not in the manifest file.
In Rails 6 there are two commented lines in application.js. Regardless of what rails version you're running just make sure you add them in:
const images = require.context('../images', true)
const imagePath = (name) => images(name, true)
Alternatively, you can force the images to be added to the manifest by moving your folder inside packs
, eg. packs/images
. The path would change though to media/images/your-file.png
.
For seeing if the path exists or not, I found it easier to just lookup it up from ruby directly:
Webpacker.manifest.send(:data).keys.grep /logo/