Reputation: 21877
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?
Upvotes: 0
Views: 2069
Reputation: 124419
You need to include the "/Users/boris/projects/chaggregator/public" portion. Paperclip includes a path
method to give this to you:
CSV.foreach(CsvUpload.last.csvfile.path) do |row|
#more code
end
Upvotes: 1