How to specify the path of the public directory in a ruby on rails app?

后端 未结 2 2229
长情又很酷
长情又很酷 2021-02-20 04:45

I want to parse .csv file which is in public folder, I\'ve tried /../\'s, #{RAILS_ROOT}/public but with no success (No such file or direct

2条回答
  •  悲&欢浪女
    2021-02-20 05:06

    You have access to the Rails.root path, use it to get a path

    Rails.root.join("public", "filename.csv")
    

    You'll possibly have to call to_s on it depending on how you want to use the result (as a Path object or as a string).

提交回复
热议问题