Rails.root
returns a Path object specifying the root of a Rails project.
Is there an equivilent for Rails engines? Like Engine.root
? If not, how else could I build up a path from the root of my Rails engine?
Well, simply put a Rails engine is the miniature edition of a Rails application. It comes with an app folder, including controllers, models, views, routes, migrations... The difference though is, that an engine won't work on its own.
Mount within the Rails routes does the equivalent of a Unix mount . It actually tells the app that another application (usually a Rack application) exists on that location. It is used mostly for Rails Engines.
Lets say your engine file is set up like this:
module MyEngine
class Engine < Rails::Engine
#......
end
end
You can call root on the Engine class like this:
MyEngine::Engine.root
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With