在生产中,不会使用图像标记调用图像的正确路径,并且不会添加md5指纹。图像名称(例如" pretty_picture.jpg")存储在数据库中。预编译文件都存在于公共文件夹中,包括清单文件。
使用image_tag调用时:
image_tag @test_question.question.image
我明白了:
<img src="/images/pretty_picture.jpg">
如果我在production.rb中设置config.assets.compile = true,则会渲染图像,然后我得到:
<img src="/assets/images/pics/pretty/pretty_picture-e0df5012b6930cda4efaa866af22a63f.jpg" >
我的黑客解决方案是使用(在HAML中)
%img{src: "/assets/"+Rails.application.assets.find_asset(@test_question.question.image).digest_path}
在production.rb中我有
config.assets.digest = true
config.assets.enabled = true
config.serve_static_files = false
config.assets.compile = false
建议不要在生产中将config.assets.compile设置为true。这似乎是代表链轮和资产管道的非常奇怪的行为。知道在这里使用image_tag有什么问题吗?
答案 0 :(得分:1)
在生产中,您应该在启动服务器之前使用以下命令预编译资产(并在每次部署时自动执行此操作):
rake assets:precompile RAILS_ENV="production"
并在config.assets.compile = false
中保留production.rb
。检查Asset Pipeline Guide。