Ruby on rails webpacker can't find images under asset_pack_path

后端 未结 5 1572
野的像风
野的像风 2021-02-06 15:16

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

5条回答
  •  灰色年华
    2021-02-06 15:35

    I had an issue with getting images to show up in Rails 6. I did this:

    Add image to

    assets/custom_folder/img_filename.file_extension
    

    Uncomment two lines in javascript/packs/application.js

    const images = require.context('../images', true)
    const imagePath = (name) => images(name, true)
    

    Then add your image to your erb file using this: (I had an index.html.erb view file)

    <%= image_tag("custom_folder/file_name.file_extension")%>
    

    This worked for me, hope it helped.

    Check out this link

提交回复
热议问题