2016-11-26 76 views
6

我想创建一个新的Ruby on Rails应用程序。每次我在rails new后键入,我得到这个错误'rails new'创建一个`validate_default_type!':选项的默认值必须与其类型匹配。 (ArgumentError)错误

/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安装在我的电脑on Rails和已经写其他的Ruby on Rails应用程序。任何想法,为什么我得到这个错误,我该如何解决它?

+1

听起来像其他一些人正在得到相同的错误。它看起来像是来自Thor gem:https://github.com/erikhuda/thor/issues/533 – heyitsjhu

+0

[Error'Validate \ _default \ _type!'可能重复:选项的默认值必须与其类型(ArgumentError)匹配“在Windows上运行Ruby on Rails时生成](http://stackoverflow.com/questions/40823526/error-validate-default-type-an-options-default-must-match-its-type-argume) –

回答

3

看来最新的宝石版本打破了它。一旦得到解决,那么这个错误应该消失。

一个临时的解决办法,如果你已经有了一个Ruby on Rails应用程序在你的Gemfile设定雷神版的最后一个版本:

gem 'thor', '0.19.1' 

或者,如果你有麻烦创建on Rails的一个新的Ruby应用程序,你可以卸载托尔和安装旧版本:

gem uninstall thor 
gem install thor -v 0.19.1 
+0

我试过宝石安装thor'0.19.1',但得到一个错误,该宝石无法找到 – Aaron

+0

这在你的Gemfile中。这不是终端的命令。 – excid3

+0

如果我无法创建应用程序,我将如何找到gem文件? – Aaron

-1

我想:

gem install thor '0.19.1'. 

我得到了:

在任何存储库中找不到有效的gem'0.19.1'(> = 0)。

埃里克迈克尔奥伯改变了雷神宝石。而rails new仅适用于Ruby on Rails 5.0版。并没有这个宝石的旧版本。 Ruby on Rails现在只能用于5.0版本。 Ruby on Rails 4.2.6已经结束。 Erik Michaels-Ober和gem杀死了旧版本的Ruby on Rails。

+0

你的命令不正确。你需要“gem install thor -v 0.19.1” – excid3

+1

谢谢! gem install thor -v 0.19.1是问题的解决方案/我与Aaron有同样的问题,并且您展示了解决方案 –

0

我有同样的问题,事实证明我必须在我的系统和我的Rails应用程序中卸载thor。

我也不能产生新的应用程序,以便在命令行,所以我必须:

gem uninstall thor 
gem install thor -v 0.19.1 

然后轨命令在命令行工作再次

我然后产生一个新的Rails应用程序,但这失败了,因为它得到了破损的版本。所以在我的宝石文件我所需要的正确的版本:

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) 

而失败的命令现在运行:

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 
0

我刚刚发现雷神0.19.3过时了,现在的作品。我只用了一周的时间就可以使用rails,所以对于其他新手我没有在应用程序的gemsfile中找到对thor的任何引用,但我只是将它添加为Benjamin所示,除了使用0.19.3并且进行了捆绑更新现在它正在工作。我之前用0.19.1做过的其他事情让我有了新的选择,但是之后无法生成脚手架。

相关问题