You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Jul 13, 2023. It is now read-only.
When Paperclip initializes Paperclip::Style objects, the Style initializer removes the :format, :geometry and :processors options from the options hash and stores them as an instance variable. The args hash that is passed in to the Style initializer is a reference to the class inheritable attribute "attachment_definitions", and these three options are removed from that hash.
When Rails class caching is on, every Style initialized after the first one will not have the :format, :geometry and :processors options passed in, because they were deleted from the class. This breaks a lot of things, particularly in our case path and url interpolations for styles with different file extensions.
We've written some Rails controller tests that demonstrate this. Unfortunately I couldn't write a test in Paperclip itself to show this problem, because there is no Rails environment in the Paperclip test suite:
class Material::Video < Material
has_attached_file :resource, {
:styles => {
:Ogg_preview => {:format => :ogg, :codec => "theora"},
:H264_preview => {:format => :mp4, :codec => "h264"}
},
:processors => [:video]
}
end
describe Material::Video do
describe "attached file" do
before do
file = fixture_file_upload("files/test.mov", 'video/quicktime')
@video = MaterialFactory.create_material({:resource => file}, creative_works(:film1).id)
@video_stem = "/system/resources/#{@video.id}"
end
it "should have an original version" do
@video.resource.url.should match "#{@video_stem}/original/test.mov?"
end
it "should create H264 preview (for Safari Users)" do
@video.resource.url(:H264_preview).should match "#{@video_stem}/H264_preview/test.mp4"
end
it "should create Ogg preview (for Firefox Users)" do
@video.resource.url(:Ogg_preview).should match "#{@video_stem}/Ogg_preview/test.ogg"
end
end
end
The fix is quite simple, just dup the style args when initializing a new Style object (in attachment.rb line 58) so that the options are not deleted from the cached class variable.
We've forked the repository and made the fix here:
git://github.com/pivotal-creationmix/paperclip.git
The text was updated successfully, but these errors were encountered:
When Paperclip initializes Paperclip::Style objects, the Style initializer removes the :format, :geometry and :processors options from the options hash and stores them as an instance variable. The args hash that is passed in to the Style initializer is a reference to the class inheritable attribute "attachment_definitions", and these three options are removed from that hash.
When Rails class caching is on, every Style initialized after the first one will not have the :format, :geometry and :processors options passed in, because they were deleted from the class. This breaks a lot of things, particularly in our case path and url interpolations for styles with different file extensions.
We've written some Rails controller tests that demonstrate this. Unfortunately I couldn't write a test in Paperclip itself to show this problem, because there is no Rails environment in the Paperclip test suite:
The fix is quite simple, just dup the style args when initializing a new Style object (in attachment.rb line 58) so that the options are not deleted from the cached class variable.
We've forked the repository and made the fix here:
git://github.com/pivotal-creationmix/paperclip.git
The text was updated successfully, but these errors were encountered: