Rails: path of file

前端 未结 4 840
庸人自扰
庸人自扰 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:45

    You should do: Rails.root.join "app", "csv", "names.csv"

    Rails.root returns a PathName object. PathName has a join method which takes any number of arguments and appends it to the pathname to create the new path.

    Read on PathName#join here:

    http://www.ruby-doc.org/stdlib-1.9.3/libdoc/pathname/rdoc/Pathname.html#method-i-join

提交回复
热议问题