ruby-on-rails - 'rails new' 创建一个 `validate_default_type!' : An option's default must match its type. (ArgumentError) 错误

标签 ruby-on-rails thor

我正在尝试创建一个新的 Ruby on Rails 应用程序。每次我输入 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,并编写了其他 Ruby on Rails 应用程序。关于为什么我会收到此错误以及如何修复它的任何想法?

最佳答案

似乎最新的 gem 版本打破了它。一旦问题得到解决,这个错误就会消失。

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

gem 'thor', '0.19.1'

或者,如果您在创建新的 Ruby on Rails 应用程序时遇到问题,您可以卸载 Thor 并安装旧版本:
gem uninstall thor
gem install thor -v 0.19.1

关于ruby-on-rails - 'rails new' 创建一个 `validate_default_type!' : An option's default must match its type. (ArgumentError) 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40823471/

相关文章:

ruby-on-rails - 使用 Thor 删除文件中的一行

ruby-on-rails - 错误消息始终包含属性名称

ruby-on-rails - 传递一个字符串作为方法参数,稍后进行插值

ruby-on-rails - 是否可以从 Thor 脚本中调用 Git 或其他命令行工具?

node.js - 在Docker中使用负载测试应用

ruby-on-rails - 如何在 Rails 中使用雷神?

ruby-on-rails - Rails 3 获取请求引用

ruby-on-rails - Rails——如何将 HAML 部分的 HTML 输出保存为字符串以发送到外部服务?

ruby-on-rails - Rails 过滤器参数过滤过多

ruby - Thor 阅读配置 yaml 文件以覆盖选项