Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error "'Validate_default_type!': An option's default must match its type (ArgumentError)" when running Ruby on Rails generate on Windows

I am following this tutorial and have just started. I have installed Ruby on Rails with gem install rails and have created a blog with rails new blog.

The tutorial now says that I need to run rails generate controller Welcome index, however when I do, I get this error:

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

I have found a similar question on Stack Overflow asking the same question here, but the poster never responded when asked to show his gem list. So here's mine:

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)

Has anybody encountered this error before? If so, how did you resolve it?

like image 340
A_toaster Avatar asked Nov 26 '16 21:11

A_toaster


4 Answers

A temporary fix is to set the version of Thor in your gemfile to the last release.

gem 'thor', '0.19.1'

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

For anyone having trouble creating a new Ruby on Rails application or anything else like middleman, you can uninstall Thor and install the older version specifically:

gem uninstall thor
gem install thor -v 0.19.1
like image 139
excid3 Avatar answered Nov 05 '22 00:11

excid3


I have had a similar issue tonight with Thor 0.19.2.

Here is what worked for me. Please ensure that you backup all data. I am very new to Rails, so I don't know what the consequences of this will be.

First, you need to remove Thor 0.19.2.

gem uninstall thor

Type 'Y' when it asks you confirm removal. Then, install the previous version of Thor.

gem install thor -v 0.19.1

You might get an error about being locked to 0.19.2 - go into your project's gemfile.lock, and find the line containing Thor. Change 0.19.2 to 0.19.1.

You might need to restart any terminal windows you have open. Good luck!

like image 41
John McCollum Avatar answered Nov 05 '22 00:11

John McCollum


I just ran into this myself. I've been working with Rails for almost a year so I was like "Uhhhhh so do I not know what I'm doing? Orrrr?" xD.

I'm on an Ubuntu-based Linux distro.

I added this line to my Gemfile:

gem 'thor', '0.19.1'

I then ran the command "bundle update thor" to make it grab the exact version I needed. Now my generators work again.

like image 2
Matt Welke Avatar answered Nov 04 '22 23:11

Matt Welke


You can also try:

bundle update thor

It worked for me.

like image 1
TadorHead Avatar answered Nov 04 '22 23:11

TadorHead