Rails 根目录路径? [英] Rails Root directory path?
本文介绍了Rails 根目录路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何获取 Rails 应用的根目录路径?
How do I get my Rails app's root directory path?
推荐答案
在 Rails 3 和更新版本中:
In Rails 3 and newer:
Rails.root
返回一个 Pathname
对象.如果你想要一个字符串,你必须添加 .to_s
.如果你想在你的 Rails 应用程序中使用另一个路径,你可以使用 join
像这样:
which returns a Pathname
object. If you want a string you have to add .to_s
. If you want another path in your Rails app, you can use join
like this:
Rails.root.join('app', 'assets', 'images', 'logo.png')
在 Rails 2 中,您可以使用 RAILS_ROOT
常量,它是一个字符串.
In Rails 2 you can use the RAILS_ROOT
constant, which is a string.
这篇关于Rails 根目录路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文