Home > OS >  Production error: "image is not present in the asset pipeline" although it is there and wo
Production error: "image is not present in the asset pipeline" although it is there and wo

Time:12-04

I'm new to devops and can't figure out what's going on. Today we pushed a branch to production where we are using new images for a view.

Everything worked fine in development environment, but when it was promoted to production we started getting errors related to the new images not being found in the asset pipeline

  <div class="text-center my-10">
    <%= link_to t("url.static_site") do %>
      <%= image_tag "logo-white-no-background" %>
    <% end %>
  </div>

error:

The asset "logo-white-no-background" is not present in the asset pipeline.

I've tried running bundle exec rake assets:precompile locally to emulate what happens in production (as I understand everything under /assets is precompiled and served by the web server) and I don't get any errors.

The only thing that I find different in the docs is that I'm not passing the file extension in the image_tag, although like I said it is working find in development (and actually breaks if I add the extension in that environment).

Should I try forcing a pre-compile on production to see if it is loaded correctly?

What else can I try?

CodePudding user response:

You will need to add the extension to make it work in production!

It shouldn't break it in development, make sure you run rails assets:clean and rails assets:clobber to clean out the compiled assets and that you have the right file extension!

CodePudding user response:

The extension is a hint to not only browsers or but also some backend servers. Nobody forces developers to add the extension; however, you can see adding the extension as a good coding habit.

For example, your image is jpg, but the browser shows it as png. You found the image shown correctly maybe it's just happened to that browser guessed the file type correctly. In some scenarios like downloading the file from S3, if there is no extension provided, it will be served as a pdf file.

Btw, about your problem, because it didn't show the image in the production environment. You can first check the src from by inspecting the source code. If the browser cannot find the image file via that URL, the URL is just invalid. After inspecting the image's URL, you can try to generate the right URL then.

  • Related