Files are uploaded to "/cache" instead to the permanent storage

I am sure I have done something really stupid here, but I just don’t see it. While direct uploading on S3 files are stored in the “/cache” instead of the right url and this is for production. On development I don’t have this problem.

Here is my uploader

class ImageUploader < Shrine
  def generate_location(io, record: nil, name: nil, derivative: nil, metadata: {}, **options)
    # storage_key #=> :cache, :store, ... 
    # io          #=> #<File>, #<Shrine::UploadedFile>, ... 
    # record      #=> #<Photo>, #<User>, ... 
    # name        #=> :image, :avatar, ... 
    # derivative  #=> :small, :medium, :large, ... (derivatives plugin) 
    # metadata    #=> { "filename" => "nature.jpg", "mime_type" => "image/jpeg", "size" => 18573, ... } 
    # options     #=> { ... other uploader options ... } 
    return super unless record
 
    table  = record.class.table_name
    id     = record.id
    derivative = derivative ? "#{derivative}/" : ""
    # The first time when the record image is not yet generated it does not have record.image
    # But the second time if we continue using just metadata["filename"] for the derivatives
    # we would get some random 'image-processing-xyz' names
    filename = record.image ? record.image.metadata["filename"] : metadata["filename"]

    "#{table}/#{record.id}/#{derivative}#{generate_uid(io)}/#{filename}"
  end

  Attacher.default_url do |derivative: nil, **|
    record.image.url if derivative
  end

  Attacher.derivatives do |original|
    magick = ImageProcessing::MiniMagick.source(original)
    { 
      p55:    magick.resize_to_limit!(98, 55),
      p169:   magick.resize_to_limit!(300, 169),
      p360:   magick.resize_to_limit!(640, 360),
      p720:   magick.resize_to_limit!(1280, 720),
      p1080:  magick.resize_to_limit!(1920, 1080)
    }
  end
  
  class Attacher < Shrine::Attacher

    def activerecord_after_save
      GenerateShrineDerivativesJob.perform_later(record)
    end

    def activerecord_after_destroy 
      # Just dont call super and keep the file
      # Sine objects at FLLCasts are softdeleted we want to 
      # handle the deletion logic in another way.
      true
    end

  end

end

Why are files in a production environment still uploaded to “/cache” and no to the url returned by generate_location is something I don’t understand.

Update 1

The generate_location method is not even called. How did I managed to get it wrong? Here is the AR

class ContentPicture < ApplicationRecord
  include ImageUploader::Attachment(:image) # adds an `image` virtual attribute 

I got it. It is really stupid.

I have though that activerecord_after_safe is actually working as the other callbacks - eg - you can define your own and it will be in addition to the others.

Turns out the attacher logic is different. There is only one method callback and if you override it, that’s it. There rest of the logic is not called

  class Attacher < Shrine::Attacher

    def activerecord_after_save
      GenerateShrineDerivativesJob.perform_later(record)
    end

Here I should have done

  class Attacher < Shrine::Attacher

    def activerecord_after_save
      GenerateShrineDerivativesJob.perform_later(record)
      super
    end