3

I wanted my seeds.rb file to have two paths based on some user input. For the sake of simplicity in this question I've stripped it down to just these two lines:

print "> "
res = gets.chomp

When I run rake db:seed, the following exception is raised:

▶ rake db:seed
> rake aborted!
Errno::ENOENT: No such file or directory @ rb_sysopen - db:seed
/home/me/work/my_app/db/seeds.rb:5:in `gets'
/home/me/work/my_app/db/seeds.rb:5:in `gets'
/home/me/work/my_app/db/seeds.rb:5:in `<top (required)>'

Anyone know why this is happening, i.e. why gets.chomp in this context is causing the program to try to open a file named db:seed?

sixty4bit
  • 7,422
  • 7
  • 33
  • 57
  • Technically I am. The arg to `rake` is `db:seed`. So that explains, a la @Glenn's answer, why it was trying to use `db:seed` as the input stream. – sixty4bit Apr 20 '16 at 16:39
  • Yeah @Glenn's answer should help you. While using ARGV in Ruby the program looks for the input from somewhere other then the `STDIN`. Personally I think it's a bug that needs to be patched, but that's just my own opinion. – 13aal Apr 20 '16 at 16:46

1 Answers1

7

Try using STDIN.gets.chomp instead of gets.chomp.

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

Community
  • 1
  • 1
Glenn
  • 540
  • 1
  • 4
  • 16