简体   繁体   English

为什么Dir.glob在Rails控制台/运行器中不起作用?

[英]Why does Dir.glob not work in Rails console/runner?

Dir.glob("*.jpg") {|_| puts 'hello'}

This works perfectly fine in IRB or a regular Rails script, but fails in Rails Console or a rails runner script. 在IRB或常规的Rails脚本中,此方法可以很好地工作,但在Rails Console或RailsRunner脚本中,此方法将失败。 Which is irritating because I really need to use it. 这很烦人,因为我真的需要使用它。 Google has no information on this that I can find. Google没有我能找到的信息。 What's the deal? 这是怎么回事?

Are there any JPG files in the root level of your app vs where you run ruby foo.rb . 与您运行ruby foo.rb位置相比,您的应用程序的根目录下是否有任何JPG文件。 I don't have any in mine, but if I tweak your code to this: 我没有任何东西,但是如果我将代码调整为:

Dir.glob("**/*.jpg") {|_| puts _}

I get all of my jpg assets like I'd expect. 我得到了所有我期望的jpg资产。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM