39

In Rails 5.1.3 I change logo file in app/assets/images Then error don't know what to fix. Any one know ?

The asset "logo.png" is not present in the asset pipeline.

Already try restart rails, rails clean, rails or rails assets:precompile

Here my config/initializers/assets.rb

# Be sure to restart your server when you modify this file.

# Version of your assets, change this if you want to expire all your assets.
Rails.application.config.assets.version = '1.0'

# Add additional assets to the asset load path.
# Rails.application.config.assets.paths << Emoji.images_path
# Add Yarn node_modules folder to the asset load path.
Rails.application.config.assets.paths << Rails.root.join('node_modules')

# Precompile additional assets.
# application.js, application.css, and all non-JS/CSS in the app/assets
# folder are already added.
# Rails.application.config.assets.precompile += %w( admin.js admin.css )
Javier Menéndez Rizo
  • 2,138
  • 3
  • 12
  • 22
PKul
  • 1,691
  • 2
  • 21
  • 41

8 Answers8

32

I had a similar problem. The solution was to add the file extension on the image.

= image_tag 'logo', alt: ''

to

= image_tag 'logo.jpg', alt: ''
Abdullah
  • 321
  • 3
  • 4
30

For me it was as simple as restarting Rails server.

BinaryButterfly
  • 18,137
  • 13
  • 50
  • 91
SkyWriter
  • 1,454
  • 10
  • 17
5

Here what I did to solve my problem assumed nothing wrong with my code and it work:

  1. Clean assets cache in /tmp/assets using this command:
$rake tmp:clear

as said here

  1. Precompile assets again using this command:
$rake assets:precompile
PKul
  • 1,691
  • 2
  • 21
  • 41
4

Try do like that

First go to

app/assets/images

Second create folder logos

app/assets/images/logos

Third put image to logos

app/assets/images/logos/logo.png

And Last put in your application put this code

<%= link_to image_tag("logos/logo.png"), root_path %>

It will be work everywhere

AzBest
  • 67
  • 5
  • great! Worked for me – Unkas Feb 06 '20 at 10:31
  • after updating rails 5 to 6 and adding the image tag without extension may give error in production but it will work find in the development, it can be fix as said add the extension with the image. – vidur punj Sep 04 '21 at 18:24
1

For rails 6, make sure your image is located inside

/app/assets/images/

Then simply

<%= image_tag("mylogo.png", size: '200x75', alt: "logo") %>
stevec
  • 41,291
  • 27
  • 223
  • 311
1

I had the same problem, tried every proposed solution in this post and no one worked... In the end, renaming the images did solve the problem, from "compuLab50-2.png" to "compusuno.png"... Also I added the <%= favicon_link_tag %> in my "layouts/application.html.erb" file. This is a very annoying and frustrating problem I think is a Rails bug (I'm using Rails 6.1.3 with webpacker by the way, which in my opinion is not much help)

Luis Flores
  • 91
  • 3
  • 14
0

I has a similar problem and nothing above helped. For me I had my whole relative path listed. so this

<%= image_tag("app/assets/.../mylogo.png", size: '200x75', alt: "logo") %>

instead just change it to

<%= image_tag("mylogo.png", size: '200x75', alt: "logo") %>

and it worked for me!

-3

the best way to solve this is to place your image file in your public folder and then with the code like this in your HTML.erb file. this is from my personal experience

<img src="/logo.png" alt="" />
  • thanks for the tip. This works if you do not want to use the asset pipeline. So I would not recomment it in this case, but for mine it was helpful – Fallenhero Mar 22 '21 at 12:40