ruby - How to mount Rails Engines automatically/dynamically? -
when using mountable engine in rails application necessary, mount engine in parent apps config/routes.rb
file this:
mount myengine::engine, at: "/my_engine"
but, possible somehow mount engine in parent app dynamically e.g. in initializer call during installation of engine bundle install
?
that's easy. can . tested , works. hope helps.
module myengine class engine < ::rails::engine isolate_namespace myengine config.my_engine = activesupport::orderedoptions.new initializer 'my_engine.configuration' |app| if app.config.my_engine[:mounted_path] app.routes.append mount myengine::engine => app.config.my_engine[:mounted_path] end end end end end
and in main application in config/application.rb, can set
config.my_engine.mounted_path = "/some_path_here"
Comments
Post a Comment