Search code examples
ruby-on-railsrails-engines

Rails engine: get parent app's name


I would like to know if a mountable Rails engine can retrieve the name of the parent application on which it is mounted.

I have looked through the official Rails engine guide, but could not find anything. Any sources or ideas?


Solution

  • I'm surprised no one answered this in more than a year. You can use:

    Rails.application.class.parent.name
    

    Depending on where you use it you might need to make sure you start at the root rails module which makes this a safer choice:

    ::Rails.application.class.parent.name