jrgifford / delayed_paperclip

Process your Paperclip attachments in the background with delayed_job or Resque.
http://www.jstorimer.com/ruby/2010/01/30/delayed-paperclip.html
MIT License
402 stars 155 forks source link

NoMethodError: undefined method `fetch' for nil:NilClass with postgres #208

Closed mvoropaiev closed 7 years ago

mvoropaiev commented 7 years ago

Hello, first of all thank you for this great gem!

I have recently switched from mysql to postgres in one project and have started to get NoMethodError: undefined methodfetch' for nil:NilClass` error when sidekick (we use it as active job adapter) tries to process the photo in background. (full log). With mysql everything worked fine with same configuration.

rails (4.2.9)
sidekiq (5.0.2)
delayed_paperclip (3.0.1)
paperclip (5.1.0)
pg (0.20.0)
Paperclip.interpolates(:placeholder) do |_attachment, _style|
  ActionController::Base.helpers.asset_path('default_image.png')
end

PAPERCLIP_PHOTOS_STORAGE_OPTS = {
      default_url: ':placeholder',
      path: ':rails_root/public:url',
      url: '/:class/:id/:style/:hash.:extension',
      hash_digest: 'SHA256',
      hash_secret: ENV.fetch('PAPERCLIP_HASHSECRET'),
      convert_options: { all: '-quality 92' }
    }.freeze

model:

has_attached_file :photo, PAPERCLIP_PHOTOS_STORAGE_OPTS.merge(
  styles: {
    large: ['1000x1000>', :jpg],
    medium: ['300x300>', :jpg],
    thumb: ['100x100>', :jpg],
    super_thumb: ['30x30>', :jpg]
  },
  only_process: [:large])
process_in_background :photo, only_process: [:medium, :thumb,
                                             :super_thumb]

validates_attachment_content_type :photo, content_type: [
  'image/jpeg',
  'image/tiff',
  'image/png'
]
validates_attachment_size :photo, less_than: 5.megabytes

Is there any gotchas or maybe I have missed something? Thank you in advance!

mvoropaiev commented 7 years ago

Okay, my bad, removing .freeze and changing PAPERCLIP_PHOTOS_STORAGE_OPTS.merge to PAPERCLIP_PHOTOS_STORAGE_OPTS.merge! seems fixed the issue, strange that it was working just fine before.