2010-07-23 33 views
1

我在thumbnail.rb說得到一個錯誤:幾何對象是空爲什麼Paperclip在我的服務器上無法找到幾何鍵?

這裏的棧的精簡版:

NoMethodError in PagesController#create 

undefined method `[]' for nil:NilClass 

RAILS_ROOT: ... 
Application Trace | Framework Trace | Full Trace 

.../vendor/plugins/paperclip/lib/paperclip/thumbnail.rb:18:in `initialize' 
.../vendor/plugins/paperclip/lib/paperclip/processor.rb:33:in `new' 
.../vendor/plugins/paperclip/lib/paperclip/processor.rb:33:in `make' 
.../vendor/plugins/paperclip/lib/paperclip/attachment.rb:295:in `post_process_styles' 
.../usr/lib/ruby/1.8/erb.rb:719:in `inject' 
.... 

我覺得這是相當奇怪的事情是,它的工作原理罰款我的本地機器,而不是零星地在我的服務器上。

我has_attached_file看起來像這樣:

has_attached_file :foreground, 
        :storage => :s3, 
        :s3_credentials => "#{RAILS_ROOT}/config/amazon_s3.yml", 
        :bucket => 'recurse', 
        :path => ":attachment/:id_partition/:token/:style/:filename", 
        :styles => { 
         :medium => {:geometry => '372x251>'}, 
         :small => {:geometry => '188x156>'}, 
         :original_strip => {:geometry => '100x100%', :processors => [:Cropper]}, 
         :medium_strip => {:geometry => '100x100%', :processors => [:MediumCropper]}, 
         :small_strip => {:geometry => '100x100%', :processors => [:SmallCropper]}, 
        } 

    has_attached_file :background, 
        :storage => :s3, 
        :s3_credentials => "#{RAILS_ROOT}/config/amazon_s3.yml", 
        :bucket => 'recurse', 
        :path => ":attachment/:id_partition/:token/:style/:filename", 
        :styles => { 
         :medium => {:geometry => '372x251>'}, 
         :small => {:geometry => '188x156>'} 
        } 

而且thumbnail.rb:18 @crop就可以了...

geometry    = options[:geometry] 
    @file    = file 
    @crop    = geometry[-1,1] == '#' 
    @target_geometry  = Geometry.parse geometry 
    @current_geometry = Geometry.from_file @file 

任何幫助將是非常有用的,因爲我沒有能夠找到任何修復此問題的東西在谷歌上。 Here's a github issue還有,如果你願意回答有,而不是/作爲

+0

謝謝。直到現在我還沒有注意到它。 – 2010-07-23 19:47:54

回答

0

這個問題似乎被固定在2.3.4 。

下面是相關變化:

@@ -55,7 +57,7 @@ 
     unless @normalized_styles 
     @normalized_styles = {} 
     (@styles.respond_to?(:call) ? @styles.call(self) : @styles).each do |name, args| 
-   @normalized_styles[name] = Paperclip::Style.new(name, args, self) 
+   @normalized_styles[name] = Paperclip::Style.new(name, args.dup, self) 
     end 
     end 
     @normalized_styles 

這就是我認爲正在發生的前2.3.4以及爲什麼這種變化解決了這個問題:

在發展中,類高速緩存通常是禁用的,而在生產它不是。請注意,以上唯一更改是args - >args.dupStyle#initialize,使用Hash#delete,正在修改樣式的原始參數,而不是副本。處理的第一個圖像獲得了所有的參數,而後面的圖像並不是因爲Style#initialize已從選項哈希中刪除了該鍵。

Google集團發佈的鏈接也解決了問題,因爲它不是修改原始哈希,而是使用Hash#reject,它返回哈希的副本並刪除了鍵。它以基本相同的方式解決了這個問題,但對代碼進行了較大的修改。

相關問題