Rails 5资产在开发中返回404。

时间:2023-01-16 16:06:13

I know this question is asked a lot, but I'm losing my mind here. I started building an app using Rails 5. I deployed to AWS EB and set the env to development. But my assets aren't loading. Getting a 404. I implemented sprockets and require 'rails/all' in my application.rb file as well as running rake assets:precompile. I also tried all the config.asset configurations in development.rb:

我知道这个问题问得很多,但我在这里失去了理智。我开始使用Rails 5构建一个应用程序。我部署了AWS EB,并将env设置为开发。但我的资产没有负担。得到一个404年。我实现了spro佝偻病,并在我的应用程序中要求使用“rails/all”。rb文件以及正在运行的rake资产:预编译。我也尝试了所有的配置。在development.rb资产配置:

config.assets_compile
config.public_file_server.enabled
config.assets.digest
config.assets.enabled

My nginx error log is full of the following for each of my assets. The path is wrong. I didn't put my assets in /var/app/current/public, I put them in /var/app/current/app/assets. At some point, I had it fetching from there (don't remember how) but it still didn't work:

对于我的每个资产,我的nginx错误日志都包含以下内容。的路径是错误的。我没有把我的资产放在/var/app/current/public中,而是放在/var/app/current/app/assets中在某些时候,我让它从那里取回(不记得是怎么取回的),但它仍然不起作用:

2017/07/28 01:16:15 [error] 2994#0: *1387 open() "/var/app/current/public/assets/merck-logo.png" failed (2: No such file or directory), client: 76.218.103.88, server: _, request: "GET /assets/merck-logo.png HTTP/1.1", host: "merckcoupons-dev1.dv3ww3wmii.us-west-1.elasticbeanstalk.com", referrer: "http://merckcoupons-dev1.dv3ww3wmii.us-west-1.elasticbeanstalk.com/circular"

The crazy thing is that I just did this with another app not too long ago and have it open as a guide. I've been googling for hours and I can't figure it out. Any help would be appreciated!

疯狂的是,我不久前刚刚用另一个应用做了这个,并把它打开作为一个指南。我在谷歌上搜索了好几个小时,都搞不清楚。如有任何帮助,我们将不胜感激!

1 个解决方案

#1


3  

When referencing images using the image_tag helper only include the filename and no path. Rails will use the file in app/assets/images in development environment and then use public/assets/IMAGE_NAME_FINGER_PRINT.ext in other environments (after pre-compilation)

当使用image_tag helper引用图像时,只包含文件名,没有路径。Rails将在开发环境中使用app/assets/image中的文件,然后使用public/assets/IMAGE_NAME_FINGER_PRINT。其他环境中的ext(预编译后)

See: http://guides.rubyonrails.org/asset_pipeline.html#coding-links-to-assets

见:http://guides.rubyonrails.org/asset_pipeline.html coding-links-to-assets

For example:

例如:

GOOD: <%= image_tag 'rails.png' %>

好:< % = image_tag rails。png”% >

BAD: <%= image_tag '/assets/rails.png' %>

缺点:< % = image_tag ' /资产/ rails。png”% >

#1


3  

When referencing images using the image_tag helper only include the filename and no path. Rails will use the file in app/assets/images in development environment and then use public/assets/IMAGE_NAME_FINGER_PRINT.ext in other environments (after pre-compilation)

当使用image_tag helper引用图像时,只包含文件名,没有路径。Rails将在开发环境中使用app/assets/image中的文件,然后使用public/assets/IMAGE_NAME_FINGER_PRINT。其他环境中的ext(预编译后)

See: http://guides.rubyonrails.org/asset_pipeline.html#coding-links-to-assets

见:http://guides.rubyonrails.org/asset_pipeline.html coding-links-to-assets

For example:

例如:

GOOD: <%= image_tag 'rails.png' %>

好:< % = image_tag rails。png”% >

BAD: <%= image_tag '/assets/rails.png' %>

缺点:< % = image_tag ' /资产/ rails。png”% >