Rails - image.png Isn't Precompiled

老子叫甜甜 提交于 2019-12-10 23:44:19

问题


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 to config.assets.compile = true

  • I've checked that the compiled image.png is in public/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!


回答1:


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 :)

Glad I could help




回答2:


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.

Hope this helps others having the same problem.

Dennis




回答3:


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.




回答4:


Resolved - needed to run rake assets:precompile RAILS_ENV='production instead of just rake assets:precompile ...
Hope this helps



来源:https://stackoverflow.com/questions/11748642/rails-image-png-isnt-precompiled

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!