【发布时间】: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