简体   繁体   English

回形针图像无法保存在生产导轨中

[英]Paperclip images failing to save in production rails

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. 我刚刚部署了一个Rails应用程序,该应用程序使用Paperclip处理文件上传到运行apache2,passenger,rails 3.2.3和ruby 1.9.3的linux ubuntu 10.04服务器。

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. 我已经在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

and my picture.rb 还有我的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 非常感谢

You need to specify paths if ImageMagick is not installed on the default paths. 如果默认路径上未安装ImageMagick,则需要指定路径。 For windows users, do something like this in initializers/paperclip.rb: 对于Windows用户,请在initializers / paperclip.rb中执行以下操作:

require "paperclip" require 'rbconfig' is_windows = (RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/) 需要“回形针”需要“ rbconfig” is_windows =(RbConfig :: CONFIG ['host_os'] =〜/ mswin | mingw | cygwin /)

Paperclip.options[:command_path] = 'C:\\ImageMagick' if is_windows Paperclip.options[:swallow_stderr] = false 如果is_windows Paperclip.options [:swallow_stderr] = false,则Paperclip.options [:command_path] ='C:\\ ImageMagick'

find the location of "identify" in your imagemagick path and put that in here. 在您的imagemagick路径中找到“标识”的位置,并将其放在此处。 Of course, you need to put the linux path in there. 当然,您需要在其中放置linux路径。 (/usr/bin/ ...) (/ usr / bin / ...)

Thanks Meduza and Hugo for pointing me in the right direction. 感谢Meduza和Hugo向我指出正确的方向。 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: 为了使图像成功上传和保存,我必须在Linux服务器上安装Imagemagick,并且还必须授予对图像路径的写入权限,如下所示:

Append with sudo if not running from root 如果不是从root运行,请附加sudo

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM