2016-11-26 27 views
16

我正在关注this tutorial并刚刚启动。我已经在gem install rails上安装了Ruby on Rails,并创建了一个rails new blog的博客。错误“Validate_default_type!”:在Windows上运行Ruby on Rails时,选项的默认值必须与其类型(ArgumentError)匹配

本教程现在说我需要运行rails generate controller Welcome index,但是当我这样做,我得到这个错误:

C:/Ruby22/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 C:/Ruby22/lib/ruby/gems/2.2.0/gems/thor-0.19.2/lib/thor/parser/option.rb:113:in `validate!' 
    from C:/Ruby22/lib/ruby/gems/2.2.0/gems/thor-0.19.2/lib/thor/parser/argument.rb:24:in `initialize' 
    from C:/Ruby22/lib/ruby/gems/2.2.0/gems/thor-0.19.2/lib/thor/parser/option.rb:9:in `initialize' 
    from C:/Ruby22/lib/ruby/gems/2.2.0/gems/thor-0.19.2/lib/thor/base.rb:544:in `new' 
    from C:/Ruby22/lib/ruby/gems/2.2.0/gems/thor-0.19.2/lib/thor/base.rb:544:in `build_option' 
    from C:/Ruby22/lib/ruby/gems/2.2.0/gems/thor-0.19.2/lib/thor/base.rb:278:in `class_option' 
    from C:/Ruby22/lib/ruby/gems/2.2.0/gems/railties-5.0.0.1/lib/rails/generators/base.rb:202:in `class_option' 
    from C:/Ruby22/lib/ruby/gems/2.2.0/gems/railties-5.0.0.1/lib/rails/generators/base.rb:178:in `block in hook_for' 
    from C:/Ruby22/lib/ruby/gems/2.2.0/gems/railties-5.0.0.1/lib/rails/generators/base.rb:168:in `each' 
    from C:/Ruby22/lib/ruby/gems/2.2.0/gems/railties-5.0.0.1/lib/rails/generators/base.rb:168:in `hook_for' 
    from C:/Ruby22/lib/ruby/gems/2.2.0/gems/jbuilder-2.6.0/lib/generators/rails/scaffold_controller_generator.rb:9:in `<class:ScaffoldControllerGenerator>' 
    from C:/Ruby22/lib/ruby/gems/2.2.0/gems/jbuilder-2.6.0/lib/generators/rails/scaffold_controller_generator.rb:6:in `<module:Generators>' 
    from C:/Ruby22/lib/ruby/gems/2.2.0/gems/jbuilder-2.6.0/lib/generators/rails/scaffold_controller_generator.rb:5:in `<module:Rails>' 
    from C:/Ruby22/lib/ruby/gems/2.2.0/gems/jbuilder-2.6.0/lib/generators/rails/scaffold_controller_generator.rb:4:in `<top (required)>' 
    from C:/Ruby22/lib/ruby/gems/2.2.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:293:in `require' 
    from C:/Ruby22/lib/ruby/gems/2.2.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:293:in `block in require' 
    from C:/Ruby22/lib/ruby/gems/2.2.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:259:in `load_dependency' 
    from C:/Ruby22/lib/ruby/gems/2.2.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:293:in `require' 
    from C:/Ruby22/lib/ruby/gems/2.2.0/gems/jbuilder-2.6.0/lib/jbuilder/railtie.rb:32:in `block in <class:Railtie>' 
    from C:/Ruby22/lib/ruby/gems/2.2.0/gems/railties-5.0.0.1/lib/rails/railtie.rb:230:in `call' 
    from C:/Ruby22/lib/ruby/gems/2.2.0/gems/railties-5.0.0.1/lib/rails/railtie.rb:230:in `block in run_generators_blocks' 
    from C:/Ruby22/lib/ruby/gems/2.2.0/gems/railties-5.0.0.1/lib/rails/railtie.rb:247:in `each' 
    from C:/Ruby22/lib/ruby/gems/2.2.0/gems/railties-5.0.0.1/lib/rails/railtie.rb:247:in `each_registered_block' 
    from C:/Ruby22/lib/ruby/gems/2.2.0/gems/railties-5.0.0.1/lib/rails/railtie.rb:230:in `run_generators_blocks' 
    from C:/Ruby22/lib/ruby/gems/2.2.0/gems/railties-5.0.0.1/lib/rails/application.rb:453:in `block in run_generators_blocks' 
    from C:/Ruby22/lib/ruby/gems/2.2.0/gems/railties-5.0.0.1/lib/rails/engine/railties.rb:13:in `each' 
    from C:/Ruby22/lib/ruby/gems/2.2.0/gems/railties-5.0.0.1/lib/rails/engine/railties.rb:13:in `each' 
    from C:/Ruby22/lib/ruby/gems/2.2.0/gems/railties-5.0.0.1/lib/rails/application.rb:453:in `run_generators_blocks' 
    from C:/Ruby22/lib/ruby/gems/2.2.0/gems/railties-5.0.0.1/lib/rails/engine.rb:465:in `load_generators' 
    from C:/Ruby22/lib/ruby/gems/2.2.0/gems/railties-5.0.0.1/lib/rails/commands/commands_tasks.rb:144:in `generate_or_destroy' 
    from C:/Ruby22/lib/ruby/gems/2.2.0/gems/railties-5.0.0.1/lib/rails/commands/commands_tasks.rb:60:in `generate' 
    from C:/Ruby22/lib/ruby/gems/2.2.0/gems/railties-5.0.0.1/lib/rails/commands/commands_tasks.rb:49:in `run_command!' 
    from C:/Ruby22/lib/ruby/gems/2.2.0/gems/railties-5.0.0.1/lib/rails/commands.rb:18:in `<top (required)>' 
    from bin/rails:4:in `require' 
    from bin/rails:4:in `<main>' 

我发现对堆栈溢出类似的问题问同样的问题here,但海报当被要求显示他的gem list时从未回应。所以这里是我的:

actioncable (5.0.0.1) 
actionmailer (5.0.0.1) 
actionpack (5.0.0.1) 
actionview (5.0.0.1) 
activejob (5.0.0.1) 
activemodel (5.0.0.1) 
activerecord (5.0.0.1) 
activesupport (5.0.0.1) 
arel (7.1.4) 
bigdecimal (1.2.7, default: 1.2.6) 
builder (3.2.2) 
bundler (1.13.6) 
coffee-rails (4.2.1) 
coffee-script (2.4.1) 
coffee-script-source (1.11.1) 
concurrent-ruby (1.0.2) 
debug_inspector (0.0.2) 
erubis (2.7.0) 
execjs (2.7.0) 
globalid (0.3.7) 
i18n (0.7.0) 
io-console (0.4.6, default: 0.4.3) 
jbuilder (2.6.0) 
jquery-rails (4.2.1) 
json (2.0.2, default: 1.8.1) 
loofah (2.0.3) 
mail (2.6.4) 
method_source (0.8.2) 
mime-types (3.1) 
mime-types-data (3.2016.0521) 
mini_portile2 (2.1.0) 
minitest (5.9.1, 5.4.3) 
multi_json (1.12.1) 
nio4r (1.2.1) 
nokogiri (1.6.8.1 x86-mingw32) 
power_assert (0.3.1, 0.2.2) 
psych (2.2.0, default: 2.0.8) 
puma (3.6.2) 
rack (2.0.1, 1.6.4) 
rack-protection (1.5.3) 
rack-test (0.6.3) 
rails (5.0.0.1) 
rails-dom-testing (2.0.1) 
rails-html-sanitizer (1.0.3) 
railties (5.0.0.1) 
rake (11.3.0, default: 10.4.2) 
rdoc (5.0.0, default: 4.2.0) 
sass (3.4.22) 
sass-rails (5.0.6) 
sinatra (1.4.7) 
sprockets (3.7.0) 
sprockets-rails (3.2.0) 
sqlite3 (1.3.12 x86-mingw32) 
test-unit (3.2.3, 3.0.8) 
thor (0.19.2, 0.19.1) 
thread_safe (0.3.5) 
tilt (2.0.5) 
turbolinks (5.0.1) 
turbolinks-source (5.0.0) 
tzinfo (1.2.2) 
tzinfo-data (1.2016.10) 
uglifier (3.0.3) 
web-console (3.4.0) 
websocket-driver (0.6.4) 
websocket-extensions (0.1.2) 

有没有人遇到过这个错误?如果是这样,你是如何解决它的?

回答

18

一个临时的解决方法是将您的gemfile中的Thor版本设置为最新版本。

gem 'thor', '0.19.1' 

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

对于有困难的人on Rails应用程序或其他任何类似中间人创建一个新的Ruby,你可以卸载雷神和具体安装旧版本:

gem uninstall thor 
gem install thor -v 0.19.1 
+3

哈哈我想我只是不幸,我试图在这个准确的时间学习Rails! 对于那些在Windows上,你可以进入你的Gemfile.lock和Ctrl + F的“Thor”,然后改变说'thor(0.19.2)'的实例为'thor(0.19.1)' –

+1

我知道对?我刚刚创建了一个全新的Rails应用程序,就像等待什么?结果发现宝石在一个小时前得到了更新,所以看起来在过去一个小时内制作新的Rails应用的任何人都会遇到这种情况。希望他们尽快修好宝石。 – excid3

+2

我必须在软件包安装前运行软件包更新 – weezilla

6

我也有过类似的问题,今晚与雷神0.19。 2。

这是什么为我工作。 请确保您备份所有数据。我对Rails很新,所以我不知道这会带来什么后果。

首先,您需要删除Thor 0.19.2。

gem uninstall thor 

当它要求您确认移除时键入'Y'。然后,安装先前版本的Thor。

gem install thor -v 0.19.1 

你可能会得到一个错误约被锁定至0.19.2 - 进入你的项目的Gemfile.lock的,并找到包含托尔行。将0.19.2更改为0.19.1。

您可能需要重新启动您打开的任何终端窗口。祝你好运!

+2

即使您希望保持一致,也不需要卸载任何版本的thor。但是您应该让软件包更新更改您的gemfile.lock文件的内容。如果您将“gem'thor','0.19.1'”添加到您的gem文件中,更新会做正确的事情。但你现在不需要0.19.3已经发布。 –

+1

感谢您的建议,我对Ruby和Rails都很陌生(如果您不知道的话) –

+1

同样在这里;) - 从字面上看,在我的第一堂课时,所有事情都因这个问题而停止了!我只知道我没有卸载任何东西,并且gemfile.lock被自动更新..;) –

2

我刚碰到这个。我一直在使用Rails几乎一年,所以我就像“呃,所以我不知道我在做什么?Orrrr?”的xD。

我在一个基于Ubuntu的Linux发行版。

我加入这行到我的Gemfile:

宝石“雷神”,“0.19.1”

然后我跑的命令“捆绑更新雷神”,使其抢我所需要的确切版本。现在我的发电机再次工作。

+2

是的 - 现在0.19.3已经发布 - 所以不需要修改gem文件 - 最新将被'捆绑更新'拾取 –

+0

哇,开源运行速度很快!我自己测试它,现在没有Gemfile变化,它现在工作正常。很高兴看到他们解决得这么快。 – Welkie

+0

@GerardONeill我强烈建议您将此添加为答案,而不仅仅是作为对所有现有答案的评论:) - 去0.19.1并不适用于我,但要达到0.19.3。 – eebbesen

0

你还可以尝试:

bundle update thor

它为我工作。

相关问题