Home > OS >  Rails path for images with bootstrap
Rails path for images with bootstrap

Time:06-30

Hello i want to use a boostrap (in my rails app) Heroes with an image and to use it i need to use img and not image_tag but that dont find my image. Here the code

<div >
    <h1 >Centered screenshot</h1>
    <div >
      <p >Quickly design and customize responsive mobile-first sites with Bootstrap, the world’s most popular front-end open source toolkit, featuring Sass variables and mixins, responsive grid system, extensive prebuilt components, and powerful JavaScript plugins.</p>
      <div >
        <button type="button" >Primary button</button>
        <button type="button" >Secondary</button>
      </div>
    </div>
    <div  style="max-height: 30vh;">
      <div >
        <img src="/images/test2.png"  alt="Example image" width="700" height="500" loading="lazy">
      </div>
    </div>
  </div>

I've tested also src="test2.png" , "/test2.png" etc...

The problem with image_tag I can't add the width, height or loading parameters.

CodePudding user response:

You can use image_path :

<img src="<%= image_path('test2.png') %>"  alt="Example image" width="700" height="500" loading="lazy">

Note that you can also use image_tag and specify any parameter including width, height, style, class ... see examples in https://apidock.com/rails/ActionView/Helpers/AssetTagHelper/image_tag

  • Related