【问题标题】:Image is 404 even though on the rails server即使在 Rails 服务器上,图像也是 404
【发布时间】:2015-08-12 12:07:44
【问题描述】:
我已经使用 railscast 上关于carrierwave 的非常好的教程将图片上传到服务器上,但我什至认为它在开发中运行良好,在生产中它不再运行了。
在我的上传器中,我有这个:
def store_dir
"images/profile/#{model.id}"
end
图片已正确上传并且存在,但是当我调用图片时收到 404...
欢迎提出任何想法。
【问题讨论】:
标签:
ruby-on-rails
image
nginx
capistrano
carrierwave
【解决方案1】:
如果您使用 Heroku 等托管服务,您将无法直接在生产环境中通过carrierwave 将文件上传到您的应用程序并期望它保留在那里(它可能会暂时出现,但不会持续很长时间)。您需要使用 aws、S3 等图像托管服务来集成和“存储”您的文件。
另外,store_dir 应该看起来更接近这样的东西
def store_dir
"uploads/#{Rails.env}/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
不确定这是您的问题,但希望对您有所帮助!