0

我剛剛部署了一個rails應用程序,它使用Paperclip來處理文件上傳到運行apache2,passenger,rails 3.2.3和ruby 1.9.3的linux ubuntu 10.04服務器。回形針圖片未能保存在生產軌道

我的設置在開發中工作得很好,但現在在生產中的圖像永遠不會保存。

我在production.rb中註釋掉了以下幾行代碼,以便rails處理文件上傳,並嘗試使用並安裝XSendFile。

# Specifies the header that your server uses for sending files 
    # config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache 
    # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx 

和我picture.rb

attr_accessible :photo_file_name, :photo_file_size, :photo_content_type, :photo, :splash_image 
    validates_presence_of :photo_file_name, :photo_content_type, :photo_file_size 


    has_attached_file :photo, 
    styles: { 
     thumb: "150x150>" 
    }, 
     url: "/assets/splash_images/:id/:style/:basename.:extension", 
     path: ":rails_root/public/assets/splash_images/:id/:style/:basename.:extension" 

    validates_attachment_size :photo, :less_than => 25.megabytes 
    validates_attachment_content_type :photo, content_type: /image/ 

有誰知道什麼可以怎麼回事?非常感謝

+0

你運行的生產運行在同一臺機器上? – Meduza

+0

您的意思是localhost? nope這是在linux vps服務器上,我還沒有在本地機器上以生產模式運行應用程序 – dodgerogers747

+1

當您上傳文件時,您可以發佈production.log中的日誌嗎? – Meduza

回答

2

感謝Meduza和Hugo爲我指出了正確的方向。爲了得到圖像上傳並保存成功,我不得不在Linux服務器上安裝ImageMagick的,也給寫權限圖片的路徑,像這樣:

追加使用sudo如果不從根本

apt-get install imagemagick 
apt-get install libmagick9-dev 
gem install rmagick 

chmod -R 777 app/app_name/public/assets/image_folder 
3

如果ImageMagick未安裝在默認路徑上,您需要指定路徑。對於Windows用戶,做這樣的事情在初始化/ paperclip.rb:

要求 「回形針」 需要 'rbconfig' is_windows = (RbConfig :: CONFIG [ 'host_os'] =〜/ mswin | MinGW的| cygwin的/)

Paperclip.options [:command_path] = 'C:\ ImageMagick的' 如果is_windows Paperclip.options [:swallow_stderr] =假

找到的 「辨識」 在你的ImageMagick路徑的位置和把它放在這裏。當然,你需要把linux路徑放在那裏。 (/ usr/bin/...)

+0

嗨雨果,我的路徑很好,因爲你提到我只是沒有任何形式的imagemagick安裝!也沒有寫入上傳文件夾的權限! – dodgerogers747