PKul
PKul

Reputation: 1711

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

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 )

Upvotes: 40

Views: 36459

Answers (9)

jose mejias
jose mejias

Reputation: 1

I had the same problem using rails 7. Since the image I needed to display was not attached to a model but was just for reference, I used this although it may not be the best way:

<img src="/logo-small.png" alt="Logo Empresa"/> 

and it worked for me. I also used this other way that also worked for me and I think it is the best of both.

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

The image is located in the public folder of the app.

Upvotes: 0

SkyWriter
SkyWriter

Reputation: 1479

For me it was as simple as restarting Rails server.

Upvotes: 30

noliver2761
noliver2761

Reputation: 1

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!

Upvotes: 0

user3630282
user3630282

Reputation:

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)

Upvotes: 1

stevec
stevec

Reputation: 52728

For rails 6, make sure your image is located inside

/app/assets/images/

Then simply

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

Upvotes: 2

nasu abdulaziz
nasu abdulaziz

Reputation: 11

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="" />

Upvotes: -2

PKul
PKul

Reputation: 1711

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

Upvotes: 5

Abdullah
Abdullah

Reputation: 321

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: ''

Upvotes: 32

AzBest
AzBest

Reputation: 67

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

Upvotes: 4

Related Questions