Ruby on rails 渲染来自其他项目的图像会导致404(未找到)错误
您好,我必须分开项目,图像项目和站点项目站点项目应仅在本地计算机的开发环境中渲染来自图像项目的图像。在生产中,它是由SDN完成的 我在“praser_路径”中共享来自秘密的图像_项目的路径 我将图像路径添加到站点\u项目中的资产配置中:Ruby on rails 渲染来自其他项目的图像会导致404(未找到)错误,ruby-on-rails,ruby,unix,carrierwave,Ruby On Rails,Ruby,Unix,Carrierwave,您好,我必须分开项目,图像项目和站点项目站点项目应仅在本地计算机的开发环境中渲染来自图像项目的图像。在生产中,它是由SDN完成的 我在“praser_路径”中共享来自秘密的图像_项目的路径 我将图像路径添加到站点\u项目中的资产配置中: # config/initializers/assets.rb if Rails.env.development? && Rails.application.secrets.parser_path # share parser image
# config/initializers/assets.rb
if Rails.env.development? && Rails.application.secrets.parser_path
# share parser images for admin
Rails.application.config.assets.paths.push(
File.join( Rails.application.secrets.parser_path, 'public', 'uploads')
)
Rails.application.config.assets.precompile += %w( advert_image/** )
end
我的模型在本地计算机中查找图像
# model/image.rb
def file_url(size=nil)
if Rails.env.development? && Rails.application.secrets.parser_path
File.join( Rails.application.secrets.parser_path, 'public', file.url(size))
else
REMOTE_HOST + file.url(size)
end
end
但是,当带有“我的图像”的页面呈现时,它会处理404,处理所有带有此错误的图像:
未能加载资源:服务器以404状态响应
(未找到)
我知道下面的链接不好,图片也不好
file:///Users/nick/CODE/work/biz/parser/public/uploads/advert_image/images/374/micro_3117094366.jpg
如何绕过服务器并直接从本地计算机渲染图像?如果粘贴
http://localhost:3000/Users/nick/CODE/work/biz/parser/public/uploads/advert_image/images/374/micro_3117094366.jpg
在您的浏览器中?我不能,但是如果我键入这个链接/Users/nick/code/work/biz/parser/public/上传/广告图片e/images/374/micro_3117094366.jpg
我可以看到图像。由于您使用应用程序URL进行访问,文件的完整路径将不起作用。您能检查一下下面的URL是否可以访问吗。