Rails: is there an Engine.root?
Ruby on-Rails-3Ruby on-Rails-3 Problem Overview
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?
Ruby on-Rails-3 Solutions
Solution 1 - Ruby on-Rails-3
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
Solution 2 - Ruby on-Rails-3
John's answer is right, but I'd clean that up a little bit like this:
When you mount your engine within your routes file add an alias first.
mount YourEngineNameHere::Engine => '/optional_namespace', as: 'your_engine_name'
Then do your_engine_name.root_url