Images will not work in Heroku - ruby-on-rails

I am building a rails app in Rails 4.0.0 and my images work just fine in production. I am using this code:
<img alt="" src="assets/ski-large2.jpg">
But when I push it to Heroku the images do not appear. I have tried changing the path to the following:
<img alt="" src="/app/assets/ski-large1.jpg">
Still does not work. In my console I get 404 file not found errors.
Any ideas?

Some recommendations.
place images under assets/images directory
instead of explicitly using <img></img> tags use:
<%= image_tag 'ski-large1.jpg' %>
<%= image_tag 'ski-large2.jpg' %>

Related

Rails image not found

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 !

Rails Wicked PDF error log (image not rendering)

I am using Rails 5 and Wicked PDF to render a PDF. On my localhost everything works fine but on my Heroku production server the image is not being rendered. First guess of course is that the image is only available on localhost but that's not the case.
If I render the same view as HTML the image is available but as PDF the image does not show.
<%= wicked_pdf_image_tag 'logo-invoice.jpg', class: 'logo' %>
It shows only a small grey square. The Rails log does not show any errors. I event tried the full URL without using Rails tags:
<img src="https://example.com/assets/logo-invoice-759b0991be66c5119a10b30680ad8902eaceacc33cfcc04afbc839d3ec404870.jpg">
Still no success. Problem is I don't know where to start debugging this?
Any ideas?
Wicked PDF can have issues rendering images from the asset pipeline. Try using the wicked_pdf_asset_base64 helper method i.e.
<%= image_tag wicked_pdf_asset_base64('logo-invoice.jpg'), class: 'logo' %>

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

Rails image_tag generating wrong path in production

I have a Rails 4.2.0 app that uses image_tag to display an image, for example:
= image_tag 'android_green_300_100px'
(It uses slim also)
In development mode, that generates the following img tag:
<img src="/assets/android_green_300_100px-3c57292ef62b34ed33756c2057c8c7320c22ac7fc7061576b29a97d312d954b1.png">
which works great.
When deploying to production with capistrano, the image file with the appropiate name is generated:
INFO -- : Writing
/home/app/releases/20160405210757/public/assets/android_green_300_100px-
3c57292ef62b34ed33756c2057c8c7320c22ac7fc7061576b29a97d312d954b1.png
But the image_tag method returns the image tag:
<img src="/images/android_green_300_100px">
Which obviously returns a 404 error.
If I manually access the correct image URL, it works (the image is there)
Any ideas? Thank you very much!
Pretty sure you have to use the file extension for image_tag to work in production:
= image_tag 'android_green_300_100px.png'
Add this line to your production.rb:
config.assets.digest = true

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