Rails new command fails if -m template is applied: "NoMethodError: private method `open' called for URI:Module"

Rails new command fails if -m template is applied: "NoMethodError: private method `open' called for URI:Module"

我一直遇到这个问题,但找不到解决方法。

当我使用模板创建新的 rails 应用程序时,生成器在 private method 'open' called for URI:Module (NoMethodError)

时失败

无论哪种方式 rails new app_name -m any_template_urlbin/rails app:template LOCATION=http://example.com/template.rb 都会 return 同样的失败。

这是终端打印出来的:

/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/thor-1.2.1/lib/thor/actions.rb:226:in `apply': private method `open' called for URI:Module (NoMethodError)

from /.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/railties-5.2.6/lib/rails/generators/app_base.rb:170:in `apply_rails_template'

from (eval):1:in `apply_rails_template'

据我所知发生了问题 when we try to open the path to the file to execute 并且 when rails tries to apply the template

我该如何解决这个问题?

对于Rails5.2推荐使用ruby2.5。更新你的ruby版本再试一次。

参考:https://www.fastruby.io/blog/ruby/rails/versions/compatibility-table.html