Errno::ENOENT (No such file or directory @ rb_sysopen

后端 未结 2 1411
萌比男神i
萌比男神i 2020-12-29 23:33

I want to write something to a file.

# where userid is any intger [sic]
path = Rails.root + \"public/system/users/#{user.id}/style/img.jpg\" 
File.open(path,         


        
2条回答
  •  青春惊慌失措
    2020-12-30 00:08

    Trying to use gets inside a rake task? You may be seeing this error message:

    Errno::ENOENT: No such file or directory @ rb_sysopen

    Did you try searching the error, and end up on this page? This answer is not for the OP, but for you.

    Use STDIN.gets. Problem solved. That's because just using gets resolves back to $stdin.gets and rake is overriding the global variable so that gets tries to open a file handle that doesn't exist. Here's why:

    What's the difference between gets.chomp() vs. STDIN.gets.chomp()?

提交回复
热议问题