5

I tried pre-compiling my images before deployment using the command:

$ RAILS_ENV=production bin/rake assets:precompile

I am using image_tag's in my templates that work in development.

Update: config.serve_static_files is said to default to true in dev, but then is turned off in production because the assets should be provided via your web server. I currently am just using the free tier on heroku and am still running webrick, so I have this set to true, but no luck.

Update 2: When I set config.serve_static_files to false, heroku does not see any of my assets, all my stylings go away and images remain unfound. Although heroku does send a warning message upon pushing to master saying that all "config.serve_static_files does is enables serving everything in the public folder and is unrelated to the asset pipeline.". I suppose it is unrelated to the asset pipeline in that it is just serving up the assets in the public folder and does not look at our assets directory. I also see that heroku runs the precompile command upon deployment, so I don't need to do that each time.

This makes me wonder if the way I am calling my assets using the image_tag could be the problem, but I am not sure why that would be?

Update 3: The rails guide for the asset pipeline says "In regular views you can access images in the public/assets/images directory like this: <%= image_tag "rails.png" %>. I am calling for my image using this convention like so <%= image_tag("lab49", size: "80x30") %>, but the image will still not appear.

Update 4: See my answer.

1
  • 1
    In case it's useful, I had the same problem on fly.io (i.e. a platform other than heroku). So I think the issue is to do with dev vs production (rather than being specific to heroku). Commented Dec 27, 2022 at 12:37

2 Answers 2

12

If you came to this post and you are using Heroku, Heroku will accept your images only if you use the image file extension.

This will work:

<%= image_tag "lab49.png", size: "80x30" %>

This will not work (although it will locally):

<%= image_tag "lab49", size: "80x30" %>
Sign up to request clarification or add additional context in comments.

3 Comments

You sir are a hero!
Confirmed this resolved the issue for me on 5.1.3. Thanks bro!
Glad it helped!
3

Something to watch out for: I had jpeg files in my assets/images folder. When I ran rake assets:precompile they were turned into .jpg files. After renaming them in my assets/images folder to .jpg, precompiling, and pushing again they displayed on Heroku just fine.

1 Comment

Same was happening to many others

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.