Error "'Validate_Default_Type!': an Option's Default Must Match Its Type (Argumenterror)" When Running Ruby on Rails Generate on Windows

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

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

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

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

UTF-8 encoding not work with gets method in Ruby

Setting the file encoding using the "magic" comment on top of the file only specifies the encoding of your source code in the file (that is: the encoding of string literals created directly from the parser in your code).

Ruby knows two other default encodings:

  • the external encoding - this specifies the default encoding of data read from external sources (such as the console, opened files, network sockets, ...)
  • the internal encoding - data read from external sources will be transformed into the default internal encoding after reading to ensure you can use compatible encodings everywhere (this is not used by default, the external encoding is thus preserved).

In your case, you have not set the external encoding. On Windows and with Ruby before version 3.0, Ruby assumes the local console encoding of your Windows installation here (such as cp850 in Western Europe).

When Ruby reads your String, it assumes it to be in cp850 encoding (or whatever your default encoding is) while you likely provide utf-8 encoded data. As spoon as you start to operate on this incorrectly encoded data, you will get errors similar to the one you have seen there.

Thus, to be able to correctly read data you need to either provide it with an encoding matching your shell encoding, or you need to tell Ruby which encoding it should assume there.

If you are providing UTF-8 encoded data, you can set the expected encoding using the -E switch when invoking ruby, e.g.:

ruby -E utf-8 your_program.rb

You can also set this in an environment variable of your Windows shell using

set RUBYOPT=-Eutf-8

In Ruby 3.0, the default external encoding on Windows was changed so that it now defaults to UTF-8 on Windows, similar to other platforms. See https://bugs.ruby-lang.org/issues/16604 for details.



Related Topics



Leave a reply



Submit