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.
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" %>
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With