2

In Rails 3, I was able to do distinguish mounted (or mountable) engines from "other" engines by calling MyEngine::Engine.class.mounted_path. This does not work in Rails 4 anymore. Based on this question, railties seem to have been deprecated.

How can I distinguish between mountable engines in Rails 4?

Community
  • 1
  • 1
RailinginDFW
  • 1,523
  • 12
  • 19

2 Answers2

3

Rails::Engine.subclasses

This will return the mounted engines.

  • this returns all engines, such as Coffee, Turbolinks and Devise. I am referring to your own custom mounted engines as shown in http://edgeguides.rubyonrails.org/engines.html – RailinginDFW Jan 12 '16 at 18:02
0

I used suggestions found [here][1] to create my own mounted_path method.

I put the following in an initializer file:

class Rails::Engine
  def self.mounted_path
    route = Rails.application.routes.routes.detect do |route|
      route.app == self
    end
    route && route.path
  end
end

Still looking for better answers. [1]: Determine if Journey::Path::Pattern matches current page

RailinginDFW
  • 1,523
  • 12
  • 19