delayed_paperclip icon indicating copy to clipboard operation
delayed_paperclip copied to clipboard

[Upgraded] For paperclip 3.1.2, with S3 fixes, and generic paperclip versions

Open tommeier opened this issue 12 years ago • 7 comments

Updated with my previous fixes to ensure it works on S3 too.

This is now working with paperclip 3.1.2, updated tests accordingly and gemfiles.

tommeier avatar Jul 02 '12 01:07 tommeier

So in gemfile :

gem 'delayed_paperclip'    , '2.4.5.2', :git => 'git://github.com/tommeier/delayed_paperclip', :branch => 'fix_312'

tommeier avatar Jul 02 '12 01:07 tommeier

Good point @timols, i'll update now.

tommeier avatar Jul 02 '12 01:07 tommeier

Removed unnecessary line and made sure a test checks the resulting value in case paperclip changes their API.

tommeier avatar Jul 02 '12 01:07 tommeier

The redefinition of the most_appropriate_url doesn't work for me, it's still the original Paperclip::UrlGenerator one that is called. Also why not just creating a new UrlGenerator inheriting from Paperclip::UrlGenerator? You could just modify the default options to use it then. Here's what I did in my app:

module Paperclip
  class MyUrlGenerator < UrlGenerator

    def for(style_name, options)
      escape_url_as_needed(
        timestamp_as_needed(
          @attachment_options[:interpolator].interpolate(most_appropriate_url(options), @attachment, style_name),
          options
      ), options)
    end

    private

    def most_appropriate_url(options)
      if @attachment.original_filename.nil? || (!options[:without_processing] && @attachment.delayed_default_url?)
        default_url
      else
        @attachment_options[:url]
      end
    end
  end
end

And then in my model

Class Image < ActiveRecord::Base
    has_attached_file(:resource, :url_generator => Paperclip::MyUrlGenerator, ... )
    ...
end

bastien avatar Jul 10 '12 13:07 bastien

Oh, I also had another problem with your patch, you can't call reprocess! directly anymore, it won't do anything, you need to call process_delayed!. Maybe more a note than an issue as it's not something you want to call too often.

bastien avatar Jul 10 '12 13:07 bastien

@bastien good idea, just want to work out a cleaner way to make it apply across the board when using delayed_paperclip, didn't have time to sort it out, so the quick hack won in the end unfortunately.

Calling reprocess! is working fine in prod for us?

tommeier avatar Jul 11 '12 03:07 tommeier

@tommeier is it because you set the attachment post_processing to true manually?

bastien avatar Jul 11 '12 08:07 bastien