How to get a list of all engines in a Rails 3 application

According to Rails, engines extend functionality in Rails 2.x could be done

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

This code does not work in Rails 3

 ActionController::RoutingError (undefined method `new' for Rails::Initializer:Module): config/application.rb:12:in `require_or_load' 

What do I need to do in Rails 3 to get such a list of engines?

This is required to extend the Rails 3 Engine controllers in the main application.

+7
source share
4 answers

Starting on 10/10/2011 and Rails 3.1 beta, now

 Rails::Application::Railties.engines 
+13
source

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

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

Here's a link to a commit on github that makes changes (and also shows how it was implemented after the 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 
+14
source

Try:

 Rails::Application.railties.engines 
+2
source

For Rails 4, the best way is:

 Rails.application.railties 
0
source

All Articles