Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Image without extension works in Dev environment but raises error in Production #729

Open
georgeu2000 opened this issue Jan 4, 2022 · 3 comments

Comments

@georgeu2000
Copy link

This is a nasty bug that has affected us twice last year and took down Production.

I see a PR was submitted but never merged and there was no explanation if the PR was lacking in some way.

https://github.com/rails/sprockets-rails/pull/461/files

This is currently an issue in Rails: rails/rails#42784
Previous issue in Rails: rails/rails#35651

Expected behavior

If an image is missing extension in Development environment, it should raise Sprockets::Rails::Helper::AssetNotFound error.

<%= image_tag 'image' %>

Actual behavior

If the image is missing extension in Development environment, it renders fine.

However, it raises Sprockets::Rails::Helper::AssetNotFound error in Production environment.

System configuration

sprockets (4.0.2)
sprockets-rails (3.2.2)
Rails 6.0.3.4
ruby 2.7.2p137

Example App (Reproduction) - THIS IS IMPORTANT YOUR ISSUE LIKELY WILL NOT BE RESOLVED WITHOUT THIS

There was an example app provided.

https://github.com/gadikotamohan/image_test

rails/rails#35651 (comment)

A PR has already been created.

@siaw23-retired
Copy link

I tried to play with this a bit. I used your Rails and Ruby versions but didn't get the error that raised for you, i.e. Sprockets::Rails::Helper::AssetNotFound

In a development environment both of these work

<%= image_tag "cat" %>
<%= image_tag "cat.jpeg" %>

In a production environment with rails s -e production, I get ActionView::Template::Error (The asset "cat" is not present in the asset pipeline. For when I use both

<%= image_tag "cat" %>
<%= image_tag "cat.jpeg" %>

If I set config.assets.compile = true in production.rb, in production however, the image shows up for me with no errors raised for both

<%= image_tag "cat" %>
<%= image_tag "cat.jpeg" %>

I've seen others file similar issues; I wasn't able to reproduce any of them. Maybe I'm missing something?

@georgeu2000
Copy link
Author

georgeu2000 commented Feb 5, 2022

Not sure if it could be because you are using both cat and cat.jpeg, or maybe I because am running

RUN bundle exec rails assets:clobber
RUN bundle exec rails assets:precompile

I did some more research and found this is a known issue.

@PatrickKing
Copy link

PatrickKing commented May 25, 2023

The example given above may be stumbling over a separate issue, which is that the asset pipeline will change "jpeg" extensions into "jpg" extensions, and this will cause both calls to image_tag to fail.

I whipped up a sample app with [email protected] that should demo the issue.

The root path renders a template with:

  <div>image_tag with extension:</div>
  <%= image_tag 'golden_cat.png' %>

  <div>image_tag without extension:</div>
  <%= image_tag 'golden_cat' %>

Run the app and visit the root path to see both images. Then in config/environments/development.rb uncomment config.assets.compile = false and restart the dev server. (And, run rails assets:precompile) You should see a Sprockets::Rails::Helper::AssetNotFound raised by image_tag, but only for the second call with no file extension.

Bitten by this issue recently, would be great if this were consistent in development for everyone.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants