在 Rails 3 及更高版本中:
Rails.root
它返回一个Pathname http://www.ruby-doc.org/stdlib-1.9.3/libdoc/pathname/rdoc/Pathname.html目的。如果你想要一个字符串,你必须添加.to_s
。如果您想要 Rails 应用程序中的另一个路径,您可以使用join http://www.ruby-doc.org/stdlib-1.9.3/libdoc/pathname/rdoc/Pathname.html#method-i-join像这样:
Rails.root.join('app', 'assets', 'images', 'logo.png')
在 Rails 2 中你可以使用RAILS_ROOT
常量,它是一个字符串。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)