'rails new' 创建一个“validate_default_type!”:选项的默认值必须与其类型相匹配。 (ArgumentError) 错误

'rails new' creates a `validate_default_type!': An option's default must match its type. (ArgumentError) error

我正在尝试在 Rails 应用程序上创建一个新的 Ruby。每次我输入 rails new 之后,我都会得到这个错误

/usr/local/lib/ruby/gems/2.2.0/gems/thor-0.19.2/lib/thor/parser/option.rb:130:in `validate_default_type!': An option's default must match its type. (ArgumentError)
    from /usr/local/lib/ruby/gems/2.2.0/gems/thor-0.19.2/lib/thor/parser/option.rb:113:in `validate!'
    from /usr/local/lib/ruby/gems/2.2.0/gems/thor-0.19.2/lib/thor/parser/argument.rb:24:in `initialize'
    from /usr/local/lib/ruby/gems/2.2.0/gems/thor-0.19.2/lib/thor/parser/option.rb:9:in `initialize'
    from /usr/local/lib/ruby/gems/2.2.0/gems/thor-0.19.2/lib/thor/base.rb:544:in `new'
    from /usr/local/lib/ruby/gems/2.2.0/gems/thor-0.19.2/lib/thor/base.rb:544:in `build_option'
    from /usr/local/lib/ruby/gems/2.2.0/gems/thor-0.19.2/lib/thor/base.rb:278:in `class_option'
    from /usr/local/lib/ruby/gems/2.2.0/gems/railties-4.2.5/lib/rails/generators/base.rb:202:in `class_option'
    from /usr/local/lib/ruby/gems/2.2.0/gems/railties-4.2.5/lib/rails/generators/app_base.rb:71:in `add_shared_options_for'
    from /usr/local/lib/ruby/gems/2.2.0/gems/railties-4.2.5/lib/rails/generators/rails/app/app_generator.rb:160:in `<class:AppGenerator>'
    from /usr/local/lib/ruby/gems/2.2.0/gems/railties-4.2.5/lib/rails/generators/rails/app/app_generator.rb:159:in `<module:Generators>'
    from /usr/local/lib/ruby/gems/2.2.0/gems/railties-4.2.5/lib/rails/generators/rails/app/app_generator.rb:153:in `<module:Rails>'
    from /usr/local/lib/ruby/gems/2.2.0/gems/railties-4.2.5/lib/rails/generators/rails/app/app_generator.rb:3:in `<top (required)>'
    from /usr/local/Cellar/ruby/2.2.3/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:69:in `require'
    from /usr/local/Cellar/ruby/2.2.3/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:69:in `require'
    from /usr/local/lib/ruby/gems/2.2.0/gems/railties-4.2.5/lib/rails/commands/application.rb:2:in `<top (required)>'
    from /usr/local/Cellar/ruby/2.2.3/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:69:in `require'
    from /usr/local/Cellar/ruby/2.2.3/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:69:in `require'
    from /usr/local/lib/ruby/gems/2.2.0/gems/railties-4.2.5/lib/rails/cli.rb:14:in `<top (required)>'
    from /usr/local/Cellar/ruby/2.2.3/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:69:in `require'
    from /usr/local/Cellar/ruby/2.2.3/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:69:in `require'
    from /usr/local/lib/ruby/gems/2.2.0/gems/railties-4.2.5/bin/rails:9:in `<top (required)>'
    from /usr/local/bin/rails:23:in `load'
    from /usr/local/bin/rails:23:in `<main>' 

我的计算机上安装了 Ruby on Rails 并且在 Rails 应用程序上编写了其他 Ruby。关于我为什么会收到此错误以及如何修复它的任何想法?

最新的 gem 版本似乎破坏了它。修复后,此错误应该会消失。

如果您在 Rails 应用程序上已有 Ruby,则临时修复是将 Gemfile 中的 Thor 版本设置为最新版本:

gem 'thor', '0.19.1'

或者,如果您在 Rails 应用程序上创建新的 Ruby 时遇到问题,您可以卸载 Thor 并安装旧版本:

gem uninstall thor
gem install thor -v 0.19.1

我试过了:

gem install thor '0.19.1'. 

我得到了:

Could not find a valid gem '0.19.1' (>= 0) in any repository.

Erik Michaels-Ober 改变了雷神gem。 rails new 仅适用于 Ruby on Rails v. 5.0。而且这个 gem 没有旧版本。 Ruby on Rails 现在仅适用于 5.0 版。 Ruby 上 Rails 4.2.6 结束了。 Erik Michaels-Ober 和 gem 在 Rails 上杀死了旧版本的 Ruby。

我遇到了同样的问题,结果我不得不在我的系统和我的 rails 应用程序中卸载雷神。

我也无法在命令行中生成新的应用程序,所以我不得不:

gem uninstall thor
gem install thor -v 0.19.1

然后 rails 命令再次在命令行中工作

然后我生成了一个新的 rails 应用程序,但这失败了,因为它得到了损坏的版本。所以在我的 gem 文件中,我需要正确的版本:

gem 'thor', '0.19.1'

然后是运行

bundle install

哦,不!

"You have requested:
  thor = 0.19.1

The bundle currently has thor locked at 0.19.2.
Try running `bundle update thor`"

那么

bundle update 

瞧! :)

Using thor 0.19.1 (was 0.19.2)

现在失败的命令 运行s:

rails generate rspec:install
Running via Spring preloader in process 26996
      create  .rspec
      create  spec
      create  spec/spec_helper.rb
      create  spec/rails_helper.rb

我刚刚发现 thor 0.19.3 已经发布并且可以使用了。我只玩了一个星期 rails 所以对于其他新手我没有在我的应用程序的 gemsfile 中找到任何对 thor 的引用但是我只是按照 Benjamin 显示的那样添加它除了使用 0.19.3 并且做了捆绑包更新雷神,现在可以使用了。我之前使用 0.19.1 所做的所有其他事情都让我 rails 焕然一新,但随后未能生成脚手架。