回形针图像无法保存在生产轨道上 [英] Paperclip images failing to save in production rails

查看:204
本文介绍了回形针图像无法保存在生产轨道上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚部署了一个Rails应用程序,它使用Paperclip来处理文件上传到运行apache2,passenger,rails 3.2.3和ruby 1.9.3的linux ubuntu 10.04服务器。

我的设置在开发过程中工作得非常好,但是现在在生产中图像从不保存。

我在production.rb中注释了以下几行,以便rails处理文件上传,并尝试使用和安装XSendFile。

 #指定您的服务器用于发送文件的标头
#config.action_dispatch.x_sendfile_header =X-Sendfile#for apache
#config.action_dispatch.x_sendfile_header ='X-Accel-Redirect'#for nginx

和我的照片。 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 /

有谁知道可以做什么要继续吗?非常感谢

解决方案

感谢Meduza和Hugo指引我正确的方向。要成功上传和保存图像,我必须在Linux服务器上安装Imagemagick,并给图像路径写入权限,如下所示:



如果不运行sudo from root
$ b $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $' b
$ b chmod -R 777 app / app_name / public / assets / image_folder


Im have just deployed a rails app which uses Paperclip to handle the file uploads to a linux ubuntu 10.04 server running apache2, passenger, rails 3.2.3 and ruby 1.9.3.

My setup worked perfectly fine in development, however now in production images never save.

i have commented out the following lines in production.rb so that rails deals with the file uploads and also tried using and installing 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

and my 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/

Does anyone know what could be going on? many thanks

解决方案

Thanks Meduza and Hugo for pointing me in the right direction. To get the images uploading and saving successfully I had to install Imagemagick on the linux server and also give write permissions to the image path like so:

Append with sudo if not running from root

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

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

这篇关于回形针图像无法保存在生产轨道上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆