2

我正在尝试使用以下脚本为 pdf 文件生成 jpg,但没有成功。

https://gist.github.com/3059321

我希望有人可以为我提供一些帮助以使其正常工作。我花了相当多的时间与它作斗争。

我有一个较旧的开发环境:

shajizaidi@Spock:~/Softdev/e-mangue/script$ rails -v
Rails 2.3.8
shajizaidi@Spock:~/Softdev/e-mangue/script$ ruby -v
ruby 1.8.7 (2011-12-28 patchlevel 357) [i686-linux]

和相关的宝石:

aasm (3.0.1)
actionmailer (2.3.8, 2.2.2)
actionpack (2.3.8, 2.2.2)
activemodel (3.1.3)
activerecord (2.3.8, 2.2.2)
activeresource (2.3.8, 2.2.2)
activesupport (3.1.3, 2.3.8, 2.2.2)
arel (2.2.1)
git (1.2.5)
hpricot (0.8.5)
httpclient (2.2.4)
mysql (2.8.1)
passenger (3.0.11)
rack (1.4.0, 1.1.3)
rails (2.3.8, 2.2.2)
rake (0.9.2)
ruby-blockcache (0.2)
rubygems-update (1.5.3)
rubyist-aasm (2.1.1)
soap4r (1.5.8)

我的模型的摘录如下:

class Issue < ActiveRecord::Base
include AASM

   belongs_to :publication
   has_many :readings
   has_many :readers, :through => :readings, :class_name => "User"

   has_many :issue_metadatas, :dependent => :destroy
   has_many :table_of_contents_entries, :dependent => :destroy

   has_many :issue_ratings

   has_one :issue_status, :dependent => :destroy

   has_attached_file :pdf,
                    :url  => "/assets/:id/",
                    :path => ":rails_root/assets/docs/:id/:style/:basename.:extension",
                     :styles => {
                                 :icon => ["60X80#", :jpg], 
                                 :thumb => ["360x480#", :jpg]
                                 :large => ["X800", :jpg]
                                 },
                     :processors => [:ghostscript, :thumbnail],
                     :convert_options => {:all => ' colorspace RGB  flatten  density 300  quality 100'},
                     :path => ":page_path/:class/:id/:resource_token/:style/:filename"

   validates_presence_of     :issue_number
   validates_presence_of     :title
   validates_presence_of     :date

当我尝试上传 pdf 时,出现以下错误:

 RuntimeError (cannot generate tempfile `'):
  /home/shajizaidi/.rvm/rubies/ruby-1.8.7-p357/lib/ruby/1.8/tempfile.rb:52:in `initialize'
  lib/paperclip_processors/ghostscript.rb:17:in `new'
  lib/paperclip_processors/ghostscript.rb:17:in `make'
  app/controllers/issues_controller.rb:79:in `new'
  app/controllers/issues_controller.rb:79:in `create'

ghostscript.rb

要测试我是否通过不使用数组来更改临时文件的生成方式,例如:

dst = Tempfile.new(“#@basename})

代替:

dst = Tempfile.new([@basename, @format ? ".#{@format}" : ''])

我没有得到错误;但是当然临时文件的文件名没有正确生成。

我已经尝试对此进行了很多研究,但似乎无法找到解决方案。

4

0 回答 0