开发者

File does not exist, while using roo in Ruby-on-rails

开发者 https://www.devze.com 2023-01-14 17:30 出处:网络
I am developing a small Ruby-on-rails application. I am using \'roo\' gem to open an excel file. But rails throws an IO error while attempting to open the file. It says file does not exist.

I am developing a small Ruby-on-rails application. I am using 'roo' gem to open an excel file. But rails throws an IO error while attempting to open the file. It says file does not exist. It works fine in irb. My development machine is windows. Here is my code

file ="#{RAILS_ROOT}/public/data/import.xls"

file.gsub!("\\","/")

workbook = Excel.new(file)

开发者_StackOverflowAny help is appreciated thanks,

Abhilash


It would be worth using the File class here rather than creating the path and gsubbing file separators. For example:

file = File.join(RAILS_ROOT, 'public', 'data', 'import.xls')

I'm pretty sure you don't need to worry too much about using backslashes for file separators though in Windows (I've stopped developing on windows though so can't test).

You can then test whether ruby thinks the file exists by doing File.exists?(file) prior to doing anything roo-specific.

Also, are you running your rails app and console as different users? That might cause some permissions problems in one but not the other.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号