Rails: is there Engine.root?

Rails.root returns a Path object that defines the root of the Rails project.

Is there an equivalent engine for Rails? How is Engine.root ? If not, how else can I create a path from the root of my Rails engine?

+50
ruby-on-rails-3
Feb 25 2018-11-21T00:
source share
2 answers

Suppose your engine file is configured as follows:

 module MyEngine class Engine < Rails::Engine #...... end end 

You can call root in the Engine class as follows:

 MyEngine::Engine.root 
+102
Feb 26 '11 at 4:58
source share

John's answer is right, but I would fix it a bit:

When you mount your engine in the routes file, first add an alias.

 mount YourEngineNameHere::Engine => '/optional_namespace', as: 'your_engine_name' 

Then do your_engine_name.root_url

0
04 Oct '17 at 18:49
source share



All Articles