Rails: path of file

前端 未结 4 790
庸人自扰
庸人自扰 2021-02-03 19:20

I have inside app a directory called csv and inside this dir I have a file called names.csv I want to use File.read(path:string)

4条回答
  •  盖世英雄少女心
    2021-02-03 19:42

    Rails.root points to the top folder of your rails project, so the path would be:

    File.read(File.join(Rails.root, 'app','csv','names.csv'))
    

提交回复
热议问题