开发者

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, h开发者_开发百科ow else could I build up a path from the root of my Rails engine?


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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜