delayed_paperclip icon indicating copy to clipboard operation
delayed_paperclip copied to clipboard

NoMethodError: undefined method `[]=' for nil:NilClass with multiple attachments

Open sowenjub opened this issue 10 years ago • 4 comments

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,

sowenjub avatar Apr 13 '14 22:04 sowenjub

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

licatajustin avatar May 18 '14 00:05 licatajustin

@licatajustin I just ordered my code as explained above.

sowenjub avatar May 19 '14 06:05 sowenjub

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

barrycollier avatar Jun 10 '14 20:06 barrycollier

+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

charlotte-miller avatar Jan 15 '15 23:01 charlotte-miller