Rails: How to convert <img src= > to image_tag in rails app

If I am not mistaken you have a rand_front folder in your assets folder so you should call image_tag("#{@random_image}") since by default the image_tag helper should check all the folders in the assets directory for the image name

For the CSS properties you can consider using the options hash which would allow you to pass in the CSS properties as keys with your desired values

image_tag("#{@random_image}", height: 20, width: 20) You can check out the documentation in the previous answer


<%= image_tag "rand_front/#{@random_image}", style: 'height:50vw;width:100vw;margin-bottom:20px;' %>

image_tag will automatically add assets at start of the path

check Image Tag for Documentation


This is what Ruby on Rails is explicitly processing

 <%= image_tag("source", {:style => "width:100px;"}) %>

(meaning that Ruby allows you to use this code with out the ( { } ),

For me, first starting out its important to know that this is how Ruby on Rails actually running the code.

In other words YES you could leave the ( { } ) formality out because Ruby will understand your code, hope that helps to clarify some...