Rails Paperclip Processor:shell命令失败

时间:2012-10-06 18:58:06

标签: ruby-on-rails ruby shell ubuntu paperclip

我的rails应用程序中的自定义回形针处理器出了问题。我上传了一个声音文件,处理器通过shell命令创建一个波形图像(由gem提供)

我在Ubuntu 12.04(生产环境)上运行RoR 3.2.7 / Ruby 1.9.3。带回形针附件的模型如下所示:

# encoding: utf-8
class Track < ActiveRecord::Base
  has_attached_file :original_file,
                    :styles => { :waveform_image => { :waveform => true } },
                    :processors => [:sound_processor],
                    :storage => :s3,
                    :s3_credentials => "#{Rails.root.to_s}/config/s3.yml",
                    :url  => ":s3_eu_url",
                    :path => "sounds/:id/:five_digit_id_:basename_:style.:extension"
end

相应的回形针处理器:

class Paperclip::SoundProcessor < Paperclip::Processor

  def initialize file, options = {}, attachment = nil
    # cut for brevity
  end

  def make
    src = @file
    dst = Tempfile.new([@basename, @current_format])
    dst.binmode

    if @waveform
      cmd = "waveform #{File.expand_path(src.path)} #{File.expand_path(dst.path)}"
      Paperclip.log(cmd)
      out = `#{cmd}`
      dst = File.open "#{File.expand_path(dst.path)}"
    end

    dst
  end
end

当命令

waveform #{File.expand_path(src.path)} #{File.expand_path(dst.path)}

正在生产机器上执行(Ubuntu 12.04),出现以下错误:

/usr/bin/env: ruby: No such file or directory

然而,usr / bin / env是一个文件而不是目录。由于没有ruby可执行文件,如何在执行shell命令时传递正确的位置?

PS:在我的开发机器(OSX)上,usr / bin / env是我的rails app目录的副本。它的工作就像一个发展的魅力。感谢您的帮助!

1 个答案:

答案 0 :(得分:0)

错误消息表明找不到ruby可执行文件。它与您目前在问题中包含的代码无关。

错误来自包含waveform #{File.expand_path(src.path)} #{File.expand_path(dst.path)}行的脚本文件。

查看以下问题的答案: - https://stackoverflow.com/a/6126419/429758 - https://stackoverflow.com/a/5241638/429758 - https://stackoverflow.com/a/5241593/429758 - https://stackoverflow.com/a/1064319/429758

他们应该让您知道为什么在您的生产环境中找不到ruby可执行文件。