What's the Rails.root equivalent in a Rack application?

陌路散爱 提交于 2019-12-11 04:14:59

问题


I'm familiar with the Rails.root in Rails which tells you the directory of your current application. This is quite handy sometimes.

Now I'm developing a Rack application (on which Rails is based). How do I find out the Rails.root equivalent for a Rack application?

Thank you.


回答1:


This returns the root directory in a string.

Rack::Directory.new('').root

Not sure if there's a better, shorter syntax.




回答2:


What worked for me is a simple File.expand_path:

File.expand_path(File.join("log", "some_file_#{ENV["RACK_ENV"] || "development"}.log"))


来源:https://stackoverflow.com/questions/22835050/whats-the-rails-root-equivalent-in-a-rack-application

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!