Remote_url Method Undefined

I’m trying to download and store images locally from a remote location by using the remote_url plugin. However the remote_url method is not available.

class MyUploader < Shrine
  plugin :remote_url

> MyUploader.respond_to? :remote_url
=> false

However, helper methods seem to get loaded into the ActiveRecord models.

class User < ApplicationRecord
  include MyUploader[:avatar]

> :avatar_remote_url
=> true

What am I doing wrong?

MyUploader.respond_to? :remote_url
# should be true 

Can you try reloading your console window, or perhaps quitting and restarting it?

I just restarted iTerm 2 and it didn’t help, unfortunately

class User < ApplicationRecord
     include MyUploader::Attachment[:avatar], max_size: nil

The only difference word for word in my code is that I am directly including with the Attachment module as above. If that doesn’t come good, I have no idea.

oops sorry, I did add the max size config option

The remote_url plugin requires a :max_size option to be specified (it can be specified to nil). It’s possible that Zeitwerk swallowed the error for missing :max_size` while loading the uploader class, and the plugin methods didn’t end up getting defined (it happened to me before too). I think this issue is fixed in recent versions of Zeitwerk.

Anyway, this self-contained script works for me:

require "shrine"

class MyUploader < Shrine
  plugin :remote_url, max_size: nil

MyUploader.respond_to?(:remote_url) # => true

That didn’t work unfortunately. I can’t share my actual source code but it’s a large codebase so maybe something is conflicting.

Here is my full plugin declaration list:

class MyUploader < Shrine
  plugin :activerecord
  plugin :determine_mime_type
  plugin :logging, logger: Rails.logger
  plugin :remove_attachment
  plugin :validation_helpers
  plugin :processing
  plugin :versions
  plugin :delete_raw
  plugin :cached_attachment_data
  plugin :remote_url, max_size: 4.megabytes

Are you able to reproduce this in a self-contained executable script, like the one I shared?

I did just realize that this project is using version 2.13. I will try to upgrade to 3, will I run into compatibility issues?

Yes, the Shrine.remote_url method was added in version 2.19.0 (though it seems I forgot to list that in the changelog).

Regarding Shrine 3.0, it does have breaking changes, they are listed in the upgrading guide.