且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Rails 根目录路径?

更新时间:2021-12-08 00:22:32

在 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.