7

I just upgraded to Rails 6 and followed guides to make this manifest file:

//= link_tree ../fonts
//= link_tree ../images
//= link_directory ../javascripts .js
//= link_directory ../stylesheets .css

But rails complains that I haven't added assets from /images/subfolder/

How do I link to /images and everything under it?

Mirror318
  • 11,875
  • 14
  • 64
  • 106

1 Answers1

10
    //=link_tree ../images

Since this is already doing the setting up of the subdirectory for you, just have to set the image tag correctly.

so in an image tag it would be:

    <%= image_tag image_url('balloons/balloons.jpg') %>

to create a clickable link with an image tag embedded would be:

    <%= link_to image_tag(image_url('balloons/balloons.jpg')), image_url('balloons/balloons.jpg') %>

You can also use the image as a background image in css, if you're using scss with the asset_url helper

.bg-container { 
  background-image: asset_url('balloons/balloons.jpg');
  height: 400px;
  width: 400px;  
}
trh
  • 7,186
  • 2
  • 29
  • 41