[英]Why does link_to helper show wrong path in Rails production?
在我的應用中,我正在通過Carrierwave使用文件上傳功能。 我使用MiniMagick調整圖像大小並將圖像保存為大版本,如下所示:
version :large do
resize_to_limit(100, 100)
end
在視圖中,我將此稱為“大”版本:
<%= image_tag @user.avatar.url(:large) %>
在開發環境中,該圖像顯示出來,並且路徑正確:
<img src="/uploads/user/....">
但是在生產環境中 ,沒有圖像顯示,因為它呈現了錯誤的路徑 (它以appname開頭):
<img src="appname/uploads/user/....">
我將Ubuntu服務器與Nginx,Unicorn,Capistrano,Ruby 2.0.0p353和Rails 4.0.2一起使用
nginx.conf:
upstream unicorn {
server unix:/tmp/unicorn.appname.sock fail_timeout=0;
}
server {
listen 80 default deferred;
server_name appname.domain.com;
root /home/deployer/apps/appname/current/public;
location ~ ^/(assets)/ {
root /home/deployer/apps/appname/current/public;
gzip_static on; # to serve pre-gzipped version
expires max;
add_header Cache-Control public;
}
try_files $uri/index.html $uri @unicorn;
location @unicorn {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://unicorn;
}
error_page 500 502 503 504 /500.html;
client_max_body_size 4G;
keepalive_timeout 10;
}
載波上傳器:
class UserUploader < CarrierWave::Uploader::Base
include CarrierWave::MiniMagick
storage :file
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
version :large do
resize_to_limit(100, 100)
end
end
最后,它正在工作。 我不得不從production.rb中刪除該行(我最初將其放置在此處以為多個Rails應用服務):
config.relative_url_root = "/appname"
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.