How to extend the mounted engine model inside another mounted engine with a reboot of the development environment

Using Rails 3.2.2 and Ruby 1.9.2.

I have a rail-mounted engine EngineAthat declares an inheriting form of a class User ActiveRecord::Base. I have another engine EngineBthat wants to add functionality to EngineA::User. Right now, what I did is shown below:

Method 1:

#EngineA app/models/engine_a/user.rb
module EngineA
  class User < ActiveRecord::Base
    has_attached_file :avatar
    has_many :somethings
  end
end

#EngineB lib/engine_b/user.rb
module EngineB
  module User
    def self.extended obj
      obj.class_eval do
        has_many :something_elses
      end
    end
  end
end

EngineA::User.extend EngineB::User

This gives me an error uninitialized constant EngineA::User. Even when I need this particular file, I run into a problem EngineArequiring a paper clip to understand has_attached_file. This road ended when I realized that I should know and demand addiction EngineAinside EngineB.

Method 2:

, , , EngineA::User.extend EngineB::User EngineB user.rb. EngineB.

#EngineB config/initializers/my_mixin.rb
EngineA::User.extend EngineB::User

!!! , , . , , EngineA::User, mixin, . , , .

, "" ... . .

+1
1

ActionDispatch . , cache_classes false, .

EngineB.rb - :

if Rails.env.development?
    ActionDispatch::Callbacks.to_prepare do
        load "#{File.expand_path(File.dirname(__FILE__))}/../config/initializers/my_mixin.rb"
    end
end
+2

All Articles