如何在 Rails 中查找文件路径
我正在使用 Ruby CSV 库中的 .foreach 方法 我需要帮助在我的 Rails 应用程序中查找文件的路径。
CSV.foreach("path/to/file.csv") do |row|
# use row here...
end
要上传 CSV 文件,我使用 Paperclip gem,它有一个用于文件位置的方法 .url
CSV.foreach(CsvUpload.last.csvfile.url) do |row|
#more code
end
CsvUpload Load (0.2ms) SELECT `csv_uploads`.* FROM `csv_uploads` ORDER BY csv_uploads.id DESC LIMIT 1
No such file or directory - /system/csvfiles/17/original/uploadthis.csv?1305217588
:文件的实际路径是: /Users/boris/projects/chaggregator/public/system/csvfiles/17/original/uploadthis.csv?1305217588
是否有 Rails 方法来获取完整的路径?
I'm using the .foreach method from the Ruby CSV library and I need help in finding a path to a file within my rails application.
CSV.foreach("path/to/file.csv") do |row|
# use row here...
end
To upload CSV files I'm using the Paperclip gem which has a method .url for the file location:
CSV.foreach(CsvUpload.last.csvfile.url) do |row|
#more code
end
CsvUpload Load (0.2ms) SELECT `csv_uploads`.* FROM `csv_uploads` ORDER BY csv_uploads.id DESC LIMIT 1
No such file or directory - /system/csvfiles/17/original/uploadthis.csv?1305217588
The actual path of the file is: /Users/boris/projects/chaggregator/public/system/csvfiles/17/original/uploadthis.csv?1305217588
Is there a Rails method for getting the full path?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要包含“/Users/boris/projects/chaggregator/public”部分。 Paperclip 包含一个
path
方法来为您提供此信息:You need to include the "/Users/boris/projects/chaggregator/public" portion. Paperclip includes a
path
method to give this to you: