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

4

16

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?

Spear answered 26/11, 2016 at 21:50 Comment(0)
C
19

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
Ceciliacecilio answered 26/11, 2016 at 22:6 Comment(4)
Haha I guess I was just unfortunate that I tried to learn Rails at this exact time! For those on WIndows, you can go into your Gemfile.lock and Ctrl+F for "Thor" then change the instance that says thor (0.19.2) to thor (0.19.1)Spear
I know right? I just created a brand new Rails app and was like wait what?? Turns out that gem got updated about an hour ago, so looks like anyone making a new Rails app in the past hour will have run into this. Hopefully they fix the gem soon.Ceciliacecilio
No need to bundle install -- a bundle update after you modify your gem file works. Now they've released 0.19.3, which works out of the box, so no need to update your gemfile -- just do the bundle update.Mannerheim
I was having this issue as well. Even after unintalling and installing the 0.19.1 version. What @Spear stated helped me. I had to go into the project's Gemfile.lock file and change the version number there as my command line kept trying to find the 0.19.2 version and couldn't. Once I changed that line to show the 0.19.1 version number, the error stopped.Derr
U
6

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!

Unhallowed answered 26/11, 2016 at 22:11 Comment(3)
No need to uninstall thor of any version, even if you want to to be consistent. But you should let the bundle update change your gemfile.lock file's contents. The update will do the right thing if you add "gem 'thor', '0.19.1'" to your gemfile. But you don't need to now that 0.19.3 has been released.Mannerheim
Thanks for the advice, I'm new to both Ruby and Rails (if you can't tell!)Unhallowed
Same here ;) -- literally was in my first class when everything was stopped short by this problem! I just knew that I didn't have to uninstall anything, and the gemfile.lock was automagically updated.. ;)Mannerheim
F
2

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.

Femi answered 26/11, 2016 at 23:26 Comment(5)
Yep -- and now 0.19.3 has been released -- so no need to modify the gem file -- the latest will be picked up by the 'bundle update'Mannerheim
Wow, open source moves fast! I tested it myself and it works fine now without Gemfile changes. Glad to see they resolved it so quickly.Femi
@GerardONeill I urge you to add this as an answer and not just as comments on all of the existing answers :) -- going to 0.19.1 didn't work for me but going to 0.19.3 did.Discompose
@Discompose i normally try to formulate an answer that makes more sense or reduces confusion -- the problem was that these answers were all correct, especially at the time. Only the "new" release changed that. So I went through, pointing out inconsistencies, which I would have done anyway. This answer by welkie was the most correct at the time, but just needed that extra tweak. Perhaps if I had been there at the beginning i wouldn't feel as though I'd be taking credit for the best parts of other answers.Mannerheim
Hah -- witness TadorHead's answer below.Mannerheim
E
1

You can also try:

bundle update thor

It worked for me.

Edition answered 3/12, 2016 at 5:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.