I deployed my app to production and noticed that images are not served from image_tag, but are served if I use asset_path. I have my images under app/assets/images. On production I precompile them so they are in public/assets and have names such as 'image_name-fk3r23039423-0e9232.png'.
我将我的应用程序部署到生产环境中,发现图像不是从image_tag提供的,但如果我使用asset_path则会提供。我在app / assets / images下有我的图像。在生产时,我预先编译它们,使它们处于公共/资产中,并具有诸如“image_name-fk3r23039423-0e9232.png”之类的名称。
When I look at html code generated I see that my image_tag's src is
当我看到生成的html代码时,我看到我的image_tag的src是
/images/logo
while asset_path generates this:
而asset_path生成这个:
/assets/login-bg1-01eead5b47afcb7e0a951a3668ec3921e8df3f4507f70599f1b84d5efc971855.jpg
So it is correct. So I am interested why I can not serve images using image_tag 'image-name'?
所以这是正确的。所以我很感兴趣为什么我不能使用image_tag'image-name'来提供图片?
Here is my production.rb
这是我的production.rb
config.serve_static_files = true
config.assets.compile = false
config.assets.digest = true
2 个解决方案
#1
9
I resolved this by adding extension to the file. I.e I did this:
我通过添加扩展名来解决这个问题。我这样做了:
<%= image_tag 'logo.png'%> # added .png
I don't know why it didn't worked without extension as in development. So I suppose this logo image is now served from application assets, not from public.
我不知道为什么没有扩展就没有开发工作。所以我想这个徽标图像现在是从应用程序资产提供的,而不是来自公共的。
#2
0
I had an similar issue and the difference was I had to change the file extension from jpeg
to jpg
in case that helps anyone.
我有一个类似的问题,不同之处在于我必须将文件扩展名从jpeg更改为jpg,以防有人帮助。
#1
9
I resolved this by adding extension to the file. I.e I did this:
我通过添加扩展名来解决这个问题。我这样做了:
<%= image_tag 'logo.png'%> # added .png
I don't know why it didn't worked without extension as in development. So I suppose this logo image is now served from application assets, not from public.
我不知道为什么没有扩展就没有开发工作。所以我想这个徽标图像现在是从应用程序资产提供的,而不是来自公共的。
#2
0
I had an similar issue and the difference was I had to change the file extension from jpeg
to jpg
in case that helps anyone.
我有一个类似的问题,不同之处在于我必须将文件扩展名从jpeg更改为jpg,以防有人帮助。