y9v/carrierwave-base64

try to use carrierwave-base64 with nobrainer

Closed this issue · 5 comments

Hi,
i would like adapt this gem with noBrainer https://github.com/y9v/carrierwave-base64 to upload a file in Base64.
So, i update this file https://github.com/y9v/carrierwave-base64/blob/master/lib/carrierwave/base64/railtie.rb
and here we can see what has been changed

module Carrierwave
  module Base64
    # Railtie class to load the carrierwave-base64 adapters
    # Loads adapters for ActiveRecord and Mongoid
    class Railtie < Rails::Railtie
      ActiveSupport.on_load :active_record do
        ActiveRecord::Base.extend Carrierwave::Base64::Adapter
      end

      ActiveSupport.on_load :mongoid do
        Mongoid::Document::ClassMethods.include Carrierwave::Base64::Adapter
      end

      ActiveSupport.on_load :nobrainer do
        puts("extending NoBrainer ...")
        NoBrainer::Document::ClassMethods.include Carrierwave::Base64::Adapter
      end
    end
  end
end

I have found ActiveSupport.onload :nobrainer when i use in console this command

irb(main):011:0> ActiveSupport.instance_variable_get(:@loaded).keys()
=> [:i18n, :after_initialize, :before_eager_load, :action_view, :active_record, :mongoid, :nobrainer, :action_controller, :before_configuration, :action_mailer, :before_initialize, :active_job, :action_dispatch_integration_test, :action_controller_base, :active_support_test_case, :action_cable, :action_cable_channel, :action_cable_connection, :action_controller_api, :devise_controller, :devise_failure_app]

and when I use

irb(main):016:0> ActiveSupport.instance_variable_get(:@loaded)[:nobrainer]
=> []

nobrainer doesn’t seem to be loaded.
Moreover, I’m using the classNoBrainer::Document::ClassMethods like it is used in https://github.com/nviennot/carrierwave-nobrainer/blob/master/lib/carrierwave-nobrainer.rb line 150.

When I start my server, I can’t see the puts message, and I have the error message “mount_base64_uploader not defined” like if ActiveSupport.on_load(:nobrainer) was not executed.

Am I missing something? Can you please help me?

Thanks for your help.

y9v commented

Hi @arabakevin!

Did you try to use the include directly, without using ActiveSupport?

NoBrainer::Document::ClassMethods.include Carrierwave::Base64::Adapter

Hi @y9v ,
I've already found a workaround to use the library.
I use an initializers
in my config/initializers/carrierwave_base64.rb, we can see

NoBrainer::Document::ClassMethods.include Carrierwave::Base64::Adapter

It's the same than you propose.
But my issue is not to found a workaround but found a solution about the method on_load. This method not working with NoBrainer and I would like know if you have an idea about that.
Thanks.
Thanks again for your answwer.

y9v commented

Ok, thanks for the update.

To be honest, I have no clue. I did a quick check, and couldn't find anything. I would try to come back to this issue later this week

y9v commented

@sangnuce closing this, feel free to reopen if you need some help