【问题标题】:Rails Paperclip Processor: shell command failingRails 回形针处理器:shell 命令失败
【发布时间】:2012-09-27 14:09:44
【问题描述】:

我的 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 目录的副本。它在开发中就像一个魅力。感谢您的帮助!

【问题讨论】:

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


    【解决方案1】:

    错误消息表明找不到 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​​ 可执行文件。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-12-31
      • 2023-03-18
      • 2011-09-13
      • 1970-01-01
      • 2011-06-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多