4.1弹性豆茎无法找到图像url

时间:2022-08-25 09:01:31

I've uploaded a simple landing page to AWS elastic beanstalk based on Rails 4.1.

我上传了一个简单的登陆页面到AWS弹性豆茎基于Rails 4.1。

The problem is now the images are not being loaded.

现在的问题是图像没有被加载。

http://localhost/assets/image.png shows me the image.
http://webinsight.co/assets/image.png does not exist.

When I look in AWS S3, the image files are uploaded properly to AWS.

当我查看AWS S3时,图像文件被适当地上载到AWS。

Anybody else encountered the same problem before?

有人遇到过同样的问题吗?

My site: http://webinsight.co

我的网站:http://webinsight.co

1 个解决方案

#1


2  

Here's what I did that worked.

这就是我所做的。

I changed all my image paths from "/assets/image.png" to

我改变了所有的图像路径,从“/资产/图像”。png”

<%= image_tag("image.png") %>

For background images I changed it to something like

对于背景图像,我把它改成了类似的东西。

background: url(image-path('image.png')) no-repeat center center;

Then I did an assets precompilation.

然后我做了一个资产预编译。

rake assets:precompile RAILS_ENV=production

As for why this is needed, I read somewhere that there's some permissions issues with AWS S3 serving images if they are not listed in public/assets/ folder for rails projects.

至于为什么需要这样做,我在某处读到,如果没有在rails项目的公共/资产/文件夹中列出AWS S3服务图像的权限问题。

Since assets:precompile automatically creates new instances of these images in the public folder, you don't have this issue after you do the changes and dynamically list the image path.

由于资产:precompile自动在公用文件夹中创建这些图像的新实例,在进行更改并动态地列出图像路径之后,您就不会遇到这个问题。

#1


2  

Here's what I did that worked.

这就是我所做的。

I changed all my image paths from "/assets/image.png" to

我改变了所有的图像路径,从“/资产/图像”。png”

<%= image_tag("image.png") %>

For background images I changed it to something like

对于背景图像,我把它改成了类似的东西。

background: url(image-path('image.png')) no-repeat center center;

Then I did an assets precompilation.

然后我做了一个资产预编译。

rake assets:precompile RAILS_ENV=production

As for why this is needed, I read somewhere that there's some permissions issues with AWS S3 serving images if they are not listed in public/assets/ folder for rails projects.

至于为什么需要这样做,我在某处读到,如果没有在rails项目的公共/资产/文件夹中列出AWS S3服务图像的权限问题。

Since assets:precompile automatically creates new instances of these images in the public folder, you don't have this issue after you do the changes and dynamically list the image path.

由于资产:precompile自动在公用文件夹中创建这些图像的新实例,在进行更改并动态地列出图像路径之后,您就不会遇到这个问题。