How to get the list of all engines in Rails 3 app

时间秒杀一切 提交于 2019-12-03 08:12:43

As of 5/10/2011 and Rails 3.1 beta, it's now

Rails::Application::Railties.engines

This has changed with Rails 4.1. The accepted answer is deprecated and the new way to get the installed Engines for a Rails application is now:

::Rails::Engine.subclasses.map(&:instance)

Here's a reference to the commit in github making the change (and also showing how it was implemented after initial deprecation...)

If you need to use the previous solution from Rails 4.1:

module Rails
    class Engine
        class Railties
            def self.engines
                @engines ||= Rails::Engine.subclasses.map(&:instance)
            end
        end
    end
end

Try:

Rails::Application.railties.engines

For Rails 4 the best way is:

Rails.application.railties
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!