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

允我心安 提交于 2019-12-10 13:25:12

问题


I am trying to create a new Ruby on Rails application. Every time I type in rails new after, I get this error

/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>' 

I have Ruby on Rails installed on my computer and have written other Ruby on Rails applications. Any ideas of why I am getting this error and how can I fix it?


回答1:


It seems the latest gem release broke it. Once that gets fixed, then this error should go away.

A temporary fix if you already have a Ruby on Rails app is to set the version of Thor in your Gemfile to the last release:

gem 'thor', '0.19.1'

Alternatively if you are having trouble creating a new Ruby on Rails application, you can uninstall Thor and install an older version:

gem uninstall thor
gem install thor -v 0.19.1



回答2:


I had the same problem, turns out I had to uninstall thor both in my system, and in my rails app.

I also could not generate a new app so in command line, so I had to:

gem uninstall thor
gem install thor -v 0.19.1

Then rails commands works in command line again

I then generated a new rails app, but this failed to, since it get the broken version. So in my gem file I required the right version:

gem 'thor', '0.19.1'

and then run

bundle install

oh, no!

"You have requested:
  thor = 0.19.1

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

so then

bundle update 

and voila!! :)

Using thor 0.19.1 (was 0.19.2)

And the failing command now runs:

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



回答3:


i just found thor 0.19.3 is out and works now. I'm only a week into playing around with rails so for those other newbies I didn't find any reference to thor in the gemsfile in my app but I simply added it as Benjamin showed except using 0.19.3 and did the bundle update thor and it's working now. Everything else I did before with 0.19.1 got me rails new but then failed on generating a scaffolding.




回答4:


I tried:

gem install thor '0.19.1'. 

And I got:

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

Erik Michaels-Ober changed the Thor gem. And rails new works only with Ruby on Rails v. 5.0. And there are no old versions of this gem. Ruby on Rails now work only with version 5.0. Ruby on Rails 4.2.6 is over. Erik Michaels-Ober and gem kills old versions of Ruby on Rails.



来源:https://stackoverflow.com/questions/40823471/rails-new-creates-a-validate-default-type-an-options-default-must-match-i

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!