Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails: is there an Engine.root?

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?

like image 357
Nathan Long Avatar asked Feb 25 '11 13:02

Nathan Long


People also ask

What are Rails engines?

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.

What is Mount in Rails routes?

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.


1 Answers

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
like image 139
johnmcaliley Avatar answered Oct 19 '22 09:10

johnmcaliley