Hi, I’m relatively new to rails so sorry if this is really basic. I’m
trying to import a CSV file, the contents of which will then be added to
a database table but I can’t get rails to see the file. Currently i have
this:
def import_csv
CSV.open(“students.csv”, ‘r’) do |row|
p row
end
end
When I run this i get an error saying “No such file or directory -
students.csv”. The csv file is in the “public” directory generated by
the rails app. what am I doing wrong? How can I get the path to the
public directory?
When I run this i get an error saying “No such file or directory -
students.csv”. The csv file is in the “public” directory generated by
the rails app. what am I doing wrong? How can I get the path to the
public directory?
The relative path starts at your Rails app root. Try
public/students.csv. Is this method in a model, controller,
some other script?
Using `p’ won’t work in a model or controller, but you can use
logger.info to write your own text to the application log if
you like.
When I run this i get an error saying “No such file or directory -
students.csv”. The csv file is in the “public” directory generated by
the rails app. what am I doing wrong? How can I get the path to the
public directory?