Rails image not found - ruby-on-rails

I've tried searching up my issue but non of the solutions worked. I am super confused why my .png isn't showing when I run my website on localhost:3000.
This is my files structure/folders and src path for robot.png
screenshot

You should move all images in app/assets/images then use <%= asset_path 'image_name.png' %>
This is standard solution

You can do this:
<%= image_tag ("images/robot.png") %>
image_tag will automatically add assets at start of the path
Take a look at Image Tag for documentation.

I ended up saving it in new directory assets/images/logos/robot.png and using <%= image_tag ("logos/robot.png") %> and it finally worked !

Related

image_tag doesn't display external images

I have a rails 4 application and I'm using image_tags throughout the application,
I'm trying to show images on twitter. If I view the source the img src tag seems fine and I can view the image using the url that's in the img src tag.
Images in my assets folder display fine.
Any ideas what's causing this?
Thanks
It's simple, Use
<%= image_tag "https://pbs.twimg.com/media/DYKjGQLW4AAh9fI.jpg" %>
Is this something you were asking?

the image does not appear in web browser using rails 5

I have problem with my app in rails . i am creating a simple blog in rails. but images not loaded on browser . i have put images on app/assets/images.
If you put file on assets folder, you should using pipeline, like:
<%= image_tag 'profile.png' %>
Or if all you want is the path to image without tag:
<%= asset_path 'profile.png' %>
Moreover, for using path without pipeline like host/img/profile.png, you should put images on:
/public/img/profile.png

Why won't image_tag show an image on site

I'm working in Cloud 9, trying to display an image using the image_tag and I'm getting this placeholder symbol that Chrome can't find my image. I uploaded the image from my computer to assets/images/logos/light_blue.png.
I don't understand why the image doesn't show up. The code I use is:
<%= image_tag ("light_blue.png") %>
A screenshot of the code
The result in the browser
The same thing happens with a JPG.
Rails is searching for your image in the directory ./assets and not in ./assets/images/logos/light_blue.png.
If you change the path, it will work, if the image is in that folder.
<%= image_tag ('images/logos/light_blue.png') %>
The documentation gives you a few more examples.

how to insert image in rails

Using Rails, I am creating my first web-site. And I have a problem like this: I can't insert an image in my page (index.html.erb).
I put an image named "main.png" in directory "app/assets/images", and wrote that:
<img src="main.png">
But my image isn't displayed correctly. What I'm doing not right?
You should use the provided helpers by Rails to "automagically" detect paths, fingerprints, ...:
<%= image_tag "main.png" %>
Anyway, I recommend you to read the asset pipeline guides to understand how the assets works in Rails: http://guides.rubyonrails.org/asset_pipeline.html
You should use Rails helpers as markets pointed out.
By the way, the name of the image file should be the same you use as the parameter of image_tag method. You are referencing your image as main.png when the image file is main.jpg
<%= image_tag "main.jpg" %>

Ruby on Rails displaying image with image_tag src

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!
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
If your image is in assets, use:
<%= image_tag("entretien.jpg", width: 200) %>

Resources