简体   繁体   English

Rails - image.png 未预编译

[英]Rails - image.png Isn't Precompiled

I'm attempting to deploy a web application on Amazon's EC2 servers, and I have the code up on the server.我正在尝试在 Amazon 的 EC2 服务器上部署一个 Web 应用程序,并且我在服务器上安装了代码。 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:一切看起来都在工作,但是当我进入主页时,我收到一条 500 错误消息,并且production.log文件给了我以下错误:

ActionView::Template::Error (image.png isn't precompiled)
  • I've tried running rake assets:precompile ,我试过运行rake assets:precompile

  • I've changed the line in config/environments/production.rb to config.assets.compile = true我已将config/environments/production.rb的行更改为config.assets.compile = true

  • I've checked that the compiled image.png is in public/assets/manifest.yml我检查过编译后的image.pngpublic/assets/manifest.yml

but I still get the same error.但我仍然遇到同样的错误。

I'm running Rails 3.2.6 and Ruby 1.8.7.我正在运行 Rails 3.2.6 和 Ruby 1.8.7。

Thanks for your help!谢谢你的帮助!

Running rake assets:precompile RAILS_ENV=production should fix it.运行rake assets:precompile RAILS_ENV=production应该可以修复它。 If you don't provide any RAILS_ENV , Rails assumes it's development如果您不提供任何RAILS_ENV ,Rails 假定它是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.因此,作为一般规则,在生产中,始终使用 RAILS_ENV='production' 运行 rake 任务,并且您应该保持安全。

I am using Openshift from Redhat and when deployed on the server it RAKEs to the production environment automatically.我正在使用 Redhat 的 Openshift,当部署在服务器上时,它会自动进入生产环境。 I too had the same problem but only on the production server.我也有同样的问题,但只在生产服务器上。

Performing the change:执行更改:

config/environments/production.rb to config.assets.compile = true config/environments/production.rb 到 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 ] config.assets.precompile += %w[ *.png *.jpeg *.jpg *.gif ]

When deployed on the server you could then do manually:在服务器上部署后,您可以手动执行以下操作:

rake RAILS_ENV=production耙 RAILS_ENV=生产

or if you are using a server like Openshift that deploys automatically, configurations in the production.rb file will be taken into account.或者,如果您使用像 Openshift 这样自动部署的服务器,则将考虑 production.rb 文件中的配置。

In config/application.rb add a line like:config/application.rb添加如下一行:

config.assets.precompile += ['image.png']

Although, if its in public/assets/images you shouldn't have to.虽然,如果它在public/assets/images你不应该这样做。

已解决 - 需要运行rake assets:precompile RAILS_ENV='production而不仅仅是rake assets:precompile ...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM