如何在 ruby on rails 应用程序中指定公共目录的路径? [英] How to specify the path of the public directory in a ruby on rails app?
本文介绍了如何在 ruby on rails 应用程序中指定公共目录的路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想解析 public
文件夹中的 .csv 文件,我试过 /../
's, #{RAILS_ROOT}/public
但没有成功(没有这样的文件或目录错误).我不知道如何使用 Rails.public_path
(Rails.public_path/filename.csv
不起作用)请帮忙
I want to parse .csv file which is in public
folder, I've tried /../
's, #{RAILS_ROOT}/public
but with no success (No such file or directory error). I dunno exactly how to use Rails.public_path
(Rails.public_path/filename.csv
doesn't work) please help
推荐答案
您可以访问 Rails.root
路径,用它来获取路径
You have access to the Rails.root
path, use it to get a path
Rails.root.join("public", "filename.csv")
根据您希望如何使用结果(作为 Path
对象或字符串),您可能必须对其调用 to_s
.
You'll possibly have to call to_s
on it depending on how you want to use the result (as a Path
object or as a string).
这篇关于如何在 ruby on rails 应用程序中指定公共目录的路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文