Why would Paperclip be failing to find the geometry key when on my server?
I'm getting an error in thumbnail.rb saying :geometry is empty
Here's a condensed version of the stack:
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'
....
The thing I find to be rather weird is that it works fine on my local machine, and not sporadically on my server.
My has_attached_file looks like so:
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 =&g开发者_运维问答t; ":attachment/:id_partition/:token/:style/:filename",
:styles => {
:medium => {:geometry => '372x251>'},
:small => {:geometry => '188x156>'}
}
And thumbnail.rb:18 has @crop on it...
geometry = options[:geometry]
@file = file
@crop = geometry[-1,1] == '#'
@target_geometry = Geometry.parse geometry
@current_geometry = Geometry.from_file @file
Any help would be immensely useful, as I haven't been able to find anything that fixes this on google. Here's a github issue as well, if you care to reply there instead/as
Style.rb lines 18-21 need to be:
@geometry = definition[:geometry]
@format = definition[:format]
@processors = definition[:processors]
@other_args = definition.reject {|key,value|[:geometry, :format, :processors].include?(key)}
http://groups.google.com/group/paperclip-plugin/browse_thread/thread/c2f5a7ae58fff976
This problem appears to be fixed in 2.3.4.
Here's the relevant change:
@@ -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
Here's what I think is happening prior to 2.3.4 and why this change solves the problem:
In development, class caching is typically disabled, while in production it is not. Note that the only change above is args
-> args.dup
. Style#initialize
, by using Hash#delete
, was modifying the original args for a style, not a copy. The first image processed got all of the args, while later images did not because Style#initialize
had removed the key from the options Hash.
The link to the Google Group posting also fixed the problem because instead of modifying the original Hash, it uses Hash#reject
, which returns a copy of the Hash with the keys removed. It solves the problem in essentially the same way, but with a larger change to the code.
精彩评论