2010-02-26 60 views
8

我已經將我的應用程序從rails 2.3遷移到rails3,並且我有回形針問題。 我看到了paperclip git上的rails3分支。因此,我在Gemfile中添加了「gem'paperclip',::git =>'git://github.com/thoughtbot/paperclip.git',:branch =>'rails3'」並啓動命令包install 。Rails3和Paperclip

一旦回形針安裝,上傳工作正常,但不是樣式。我看到了一個修復它的黑客。

# in lib/paperclip/attachment.rb at line 293 
def callback which #:nodoc: 
    # replace this line... 
    # instance.run_callbacks(which, @queued_for_write){|result,obj| result == false } 
    # with this: 
    instance.run_callbacks(which, @queued_for_write) 
end 

之後的樣式可以,但我無法激活處理器。我的代碼是:

has_attached_file     :image, 
            :default_url => "/images/nopicture.jpg", 
            :styles => { :large => "800x600>", 
               :cropped => Proc.new { |instance| "#{instance.width}x#{instance.height}>" }, 
               :crop => "300x300>" }, 
            :processors => [:cropper] 

我處理器位於RAILS_APP/lib目錄/ paperclip_processors/cropper.rb,包含:

module Paperclip 
    class Cropper < Thumbnail 
    def transformation_command 
     if crop_command and !skip_crop? 
     crop_command + super.sub(/ -crop \S+/, '') 
     else 
     super 
     end 
    end 

    def crop_command 
     target = @attachment.instance 
     trans = ""; 
     trans << " -crop #{target.crop_w}x#{target.crop_h}+#{target.crop_x}+#{target.crop_y}" if target.cropping? 
     trans << " -resize \"#{target.width}x#{target.height}\"" 
     trans 
    end 

    def skip_crop? 
    ["800x600>", "300x300>"].include?(@target_geometry.to_s) 
    end 
end 
end 

我的問題是,我得到這個錯誤信息:未初始化不斷回形針::裁剪器 裁剪後的處理器未加載。

有人有想法解決這個問題嗎?

有關信息,我的應用程序在rails 2.3.4上正常工作。

回答

2

重新啓動服務器,爲我工作:)

0

我有同樣的問題。我使用回形針寶石從這個倉庫:

gem "paperclip", :git => "git://github.com/JasonKing/paperclip.git", :branch => "rails3" 

而且我也得到「未初始化不斷回形針::克羅珀」。重新啓動服務器不起作用!

1

我得到了「未初始化的常量Paperclip :: Cropper」異常。 但是,您可以將cropper.rb移動到回形針庫目錄並添加require'paperclip/cropper.rb'。它爲我工作,但我用捆綁,所以看起來很醜陋......

+0

我最後ly解決了問題,就像你做的一樣,除了我把回形針作爲插件安裝... 有點不那麼醜陋:P – Arkan 2010-05-17 17:18:20

0

是的,安裝回形針作爲一個插件,它會工作

5

我有同樣的問題。看起來像回形針處理器沒有加載在rails 3.直到有人修復它,我砍死了移動cropper.rb文件裏面/ config/initializers的問題

1

在你的Photo.rb類中,或者你曾經需要的「.../cropper.rb」你必須把根路徑項目的還有:

require "#{config.root}/lib/paperclip_processors/cropper.rb" # required to make cropping work. 

之前它曾經只是要求‘LIB/...’