我的应用程序已开启:
ruby-2.6.4
Rails 4.2.8
activerecord-4.2.8
我正在将 Rails 应用程序升级到
ruby-2.6.4
在开发中运行 rake 任务进行测试时,我收到 BigDecimal()
和 .../vendor/bundle/ruby/2.6.0/gems/ruby-oci8/...
的错误
ArgumentError: invalid value for BigDecimal(): "0.E+00"
/sha/git/sha_human_resources/shared/bundle/ruby/2.6.0/gems/ruby-oci8-2.1.8/lib/oci8/bindtype.rb:35:in `BigDecimal'
...
.../vendor/bundle/ruby/2.6.0/gems/ruby-oci8-2.1.8/lib/oci8/bindtype.rb:216: warning: constant ::Fixnum is deprecated
.../vendor/bundle/ruby/2.6.0/gems/ruby-oci8-2.1.8/lib/oci8/bindtype.rb:219: warning: constant ::Bignum is deprecated
.../vendor/bundle/ruby/2.6.0/gems/ruby-oci8-2.1.8/lib/oci8/compat.rb:73: warning: constant ::Fixnum is deprecated
我发现了一些关于更新
bigdecimal
和 oci8
gems 的线程,所以尝试了几个版本,发现这些有帮助:git diff Gemfile
:
-gem 'ruby-oci8', '~> 2.1.5'
+gem 'ruby-oci8', '~> 2.2.8'
并添加了一个bigdecimal gem:
+gem "bigdecimal", ">= 2.0.0"
现在,当我运行 rake 任务时,我收到此错误:
rake aborted!
NoMethodError: undefined method `new' for BigDecimal:Class
.../vendor/bundle/ruby/2.6.0/gems/activesupport-4.2.8/lib/active_support/core_ext/object/duplicable.rb:111:in `<class:BigDecimal>'
.../vendor/bundle/ruby/2.6.0/gems/activesupport-4.2.8/lib/active_support/core_ext/object/duplicable.rb:106:in `<top (required)>'
.../vendor/bundle/ruby/2.6.0/gems/activesupport-4.2.8/lib/active_support/core_ext/object.rb:3:in `require'
.../vendor/bundle/ruby/2.6.0/gems/activesupport-4.2.8/lib/active_support/core_ext/object.rb:3:in `<top (required)>'
.../vendor/bundle/ruby/2.6.0/gems/railties-4.2.8/lib/rails/configuration.rb:2:in `require'
.../vendor/bundle/ruby/2.6.0/gems/railties-4.2.8/lib/rails/configuration.rb:2:in `<top (required)>'
.../vendor/bundle/ruby/2.6.0/gems/railties-4.2.8/lib/rails/railtie.rb:2:in `require'
.../vendor/bundle/ruby/2.6.0/gems/railties-4.2.8/lib/rails/railtie.rb:2:in `<top (required)>'
.../vendor/bundle/ruby/2.6.0/gems/railties-4.2.8/lib/rails/engine.rb:1:in `require'
.../vendor/bundle/ruby/2.6.0/gems/railties-4.2.8/lib/rails/engine.rb:1:in `<top (required)>'
.../vendor/bundle/ruby/2.6.0/gems/railties-4.2.8/lib/rails/application.rb:7:in `require'
.../vendor/bundle/ruby/2.6.0/gems/railties-4.2.8/lib/rails/application.rb:7:in `<top (required)>'
.../vendor/bundle/ruby/2.6.0/gems/railties-4.2.8/lib/rails.rb:11:in `require'
.../vendor/bundle/ruby/2.6.0/gems/railties-4.2.8/lib/rails.rb:11:in `<top (required)>'
.../vendor/bundle/ruby/2.6.0/gems/railties-4.2.8/lib/rails/all.rb:1:in `require'
.../vendor/bundle/ruby/2.6.0/gems/railties-4.2.8/lib/rails/all.rb:1:in `<top (required)>'
.../config/application.rb:3:in `require'
.../config/application.rb:3:in `<top (required)>'
.../Rakefile:6:in `require'
.../Rakefile:6:in `<top (required)>'
/usr/local/rvm/rubies/ruby-2.6.4/bin/bundle:30:in `block in <main>'
/usr/local/rvm/rubies/ruby-2.6.4/bin/bundle:22:in `<main>'
/usr/local/rvm/gems/ruby-2.6.4/bin/ruby_executable_hooks:24:in `eval'
/usr/local/rvm/gems/ruby-2.6.4/bin/ruby_executable_hooks:24:in `<main>'
做了更多的谷歌冲浪,我发现没有太多关于解决这个问题的信息。 我确实看到一些提到升级到最新版本的 Rails。 必须要解决这个问题吗? 在我们准备好升级 Rails 版本之前,是否有猴子补丁或修复程序可以解决/修复/防止此问题? 我觉得我们将永远追逐最新版本的 Rails 的胡萝卜加大棒。
感谢您的任何建议。
根据 BigDecimal 的文档,对于所有 Ruby 版本 2.6.x,您应该使用具有特定版本的 BigDecimal:
各版本差异如下:
version characteristics Supported ruby version range 2.0.0 You cannot use BigDecimal.new and do subclassing 2.4 .. 1.4.x BigDecimal.new and subclassing always prints warning. 2.3 .. 2.6 1.3.5 You can use BigDecimal.new and subclassing without warning .. 2.5
您可以使用 Gemfile 或脚本中的
方法选择您要使用的版本。例如,您想坚持 bigdecimal 版本 1.3.5,可以将以下gem
调用放入 Gemfile 中。gem
gem 'bigdecimal', '1.3.5'
我看到 bigdecimal、racc、nokogiri 等之间存在大量相关的 gem 依赖冲突,将 Rails 7.0 升级到 7.1 。
从 Ruby 3.2 升级到 Ruby 3.3 解决了所有问题。