Reopening Rails 3 engine classes from parent app

喜欢而已 提交于 2019-12-05 04:51:57

In Rails 3.2.2 / Ruby 1.9 turn on reloading of plugins, then require the class in the engine using require_dependency before reopening the class and adding functionality. This works even in development environment (i.e class reloading).

# development.rb
config.reload_plugins = true 

# app/controllers/my_engine/documents_controller.rb
require_dependency MyEngine::Engine.root.join('app', 'controllers', 'my_engine', 'documents_controller').to_s

module MyEngine
  class DocumentsController
    def show
      render :text => 'different'
    end
  end
end
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!