gpt4 book ai didi

ruby-on-rails - Rails 5 Assets 在开发中返回 404

转载 作者:行者123 更新时间:2023-12-04 05:31:35 25 4
gpt4 key购买 nike

我知道这个问题被问了很多,但我在这里失去了理智。我开始使用 Rails 5 构建应用程序。我部署到 AWS EB 并将环境设置为开发。但我的 Assets 没有加载。出现 404。我在我的 application.rb 文件中实现了 sprockets 和 require 'rails/all' 以及运行 rake assets:precompile。我还尝试了 development.rb 中的所有 config.asset 配置:

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

对于我的每项 Assets ,我的 nginx 错误日志都包含以下内容。路径错误。我没有将 Assets 放在 /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"

疯狂的是,我不久前刚刚用另一个应用程序做了这个,并将其作为指南打开。我已经用谷歌搜索了几个小时,但我无法弄清楚。任何帮助将不胜感激!

最佳答案

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

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

例如:

良好:<%= image_tag 'rails.png' %>

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

关于ruby-on-rails - Rails 5 Assets 在开发中返回 404,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45363532/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com