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

前端 未结 3 1617
醉梦人生
醉梦人生 2021-02-09 05:10

According to Rails engines extending functionality in Rails 2.x one could do

Rails::Initializer.new(Rails.configuration).plugin_loader.engines

相关标签:
3条回答
  • 2021-02-09 05:28

    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
    
    0 讨论(0)
  • 2021-02-09 05:28

    Try:

    Rails::Application.railties.engines
    
    0 讨论(0)
  • 2021-02-09 05:40

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

    Rails::Application::Railties.engines
    
    0 讨论(0)
提交回复
热议问题