在Rails的公用文件夹中获取文件的绝对路径 [英] Getting absolute path to the file inside the public folder in Rails
本文介绍了在Rails的公用文件夹中获取文件的绝对路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
获取控制器公用文件夹中文件的绝对路径的最佳方法是什么?是否有预定义的Rails变量来保存公用文件夹的绝对路径?
What is the best way to get absolute path to the file inside the public folder in controller? Is there a predefined Rails variable that holds absolute path to the public folder?
当前我正在使用File.expand_path('../../../public', __FILE__)
,但是我敢肯定有一种更好的方法可以实现这一点.
Currently I'm using File.expand_path('../../../public', __FILE__)
, but I'm sure there's a nicer way of doing this.
推荐答案
Rails.public_path
应该为您提供公共路径
Rails.public_path
should provide you the public path
这篇关于在Rails的公用文件夹中获取文件的绝对路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文