Rails - image.png Isn't Precompiled
-
23-06-2021 - |
Question
I'm attempting to deploy a web application on Amazon's EC2 servers, and I have the code up on the server. Everything looks like it's working, but when I go to the home page, I get a 500 error message and the production.log
file gives me the following error:
ActionView::Template::Error (image.png isn't precompiled)
I've tried running
rake assets:precompile
,I've changed the line in
config/environments/production.rb
toconfig.assets.compile = true
- I've checked that the compiled
image.png
is inpublic/assets/manifest.yml
but I still get the same error.
I'm running Rails 3.2.6 and Ruby 1.8.7.
Thanks for your help!
Solution
Running rake assets:precompile RAILS_ENV=production
should fix it.
If you don't provide any RAILS_ENV
, Rails assumes it's development
I believe that's because each env in the asset pipeline behaves differently. Therefore, as a general rule, in production, always run rake tasks with RAILS_ENV='production' and you should stay safe.
OTHER TIPS
I am using Openshift from Redhat and when deployed on the server it RAKEs to the production environment automatically. I too had the same problem but only on the production server.
Performing the change:
config/environments/production.rb to config.assets.compile = true
worked a treat. There is another parameter in this file vou could change:
config.assets.precompile += %w[ *.png *.jpeg *.jpg *.gif ]
When deployed on the server you could then do manually:
rake RAILS_ENV=production
or if you are using a server like Openshift that deploys automatically, configurations in the production.rb file will be taken into account.
In config/application.rb
add a line like:
config.assets.precompile += ['image.png']
Although, if its in public/assets/images
you shouldn't have to.
Resolved - needed to run rake assets:precompile RAILS_ENV='production
instead of just rake assets:precompile
...