Ruby on Rails displaying image with image_tag src

27,922

Solution 1

rails 3.1 n later have a new feature called 'asset pipeline', u can read it at http://guides.rubyonrails.org/asset_pipeline.html

u can access the image in the view as

= image_tag "/assets/large/icon.png"

the image 'icon.png' resides in 'large' under 'images' in 'assets'

to see how to refer the same image in css, see Rails 3.1 and Image Assets

Solution 2

If your image is in assets, use:

<%= image_tag("entretien.jpg", width: 200) %>
Share:
27,922
hellomello
Author by

hellomello

On the path to learning all things React Native at the moment. I'll be right back!

Updated on June 11, 2020

Comments

  • hellomello
    hellomello almost 4 years

    I have an image in my app/assets/images folder and I'm in my view page trying to display an image.

    <%= image_tag "NoAvatar.png" %>
    

    When I load my page in localhost my image only shows /assets/ in its src path

    <img alt="Assets" src="/assets/">
    

    I'm not understanding why this is the issue? Am I doing something wrong? I thought this was how its supposed to link to an image in your pipeline?

    Thanks!