Rails engines extending functionality

前端 未结 6 761
夕颜
夕颜 2020-12-01 06:50

I have an engine which defines some models and controllers. I want to be able to extend functionality of some models/controllers in my application (eg. adding methods) witho

6条回答
  •  鱼传尺愫
    2020-12-01 07:29

    You can change the load order of the engine to avoid the require on each of your models.

    In config/application.rb add this line:

    module MyApp
      class Application
        config.railties_order = [MyEngine::Engine, :main_app, :all]
      end
    end
    

    This will ensure that the models from MyEngine are loaded before MyApp

提交回复
热议问题