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 `[]=' for nil:NilClass with multiple attachments #83

Open sowenjub opened 10 years ago

sowenjub commented 10 years ago

Hi,

I don't know whether it can be fixed or just something that should be mentioned somewhere in the docs, but if you have 2 attachments on the same model, the following will cause "NoMethodError: undefined method []=' for nil:NilClass in delayed_paperclip-2.7.1/lib/delayed_paperclip.rb:51:inprocess_in_background'":

has_attached_file :first
process_in_background :first
has_attached_file :second
process_in_background :second

while this will work

has_attached_file :first
has_attached_file :second
process_in_background :first
process_in_background :second

Best,

licatajustin commented 10 years ago

+1. Have you found a solution for this @sowenjub?

sowenjub commented 10 years ago

@licatajustin I just ordered my code as explained above.

barrycollier commented 10 years ago

+1. Thanks for posting your workaround, @sowenjub. It worked for me as well.

charlotte-miller commented 9 years ago

+1 on fixing this bug. I use an ActiveSupport::Concern to handle my Paperclip config, so re-ordering the methods is non-trivial. Example:

# app/models/concerns/attachable_file.rb
def has_attachable_file( attachment_name, options={} )      
  class_eval do
    has_attached_file attachment_name, {
      paperclip_config_stuff:  => :etc,
      }.deep_merge(options)

      process_in_background attachment_name
   end
end

# app/models/user.rb
has_attachable_file :profile
has_attachable_file :cover_art