简体   繁体   English

NoMethodError:BigDecimal 的未定义方法“新”:Class

[英]NoMethodError: undefined method `new' for BigDecimal:Class

Recently I have updated Ruby(2.5.3 to 2.7.1) and Ruby on rails(5.2.2 to 6.1.1) version.最近我更新了 Ruby(2.5.3 到 2.7.1)Ruby on rails(5.2.2 到 6.1.1)版本。

After that when I run rspec , I got this error:之后,当我运行rspec时,出现此错误:

Failure/Error: require File.expand_path("../../config/environment", __FILE__)
NoMethodError:
  undefined method `new' for BigDecimal:Class
# ./config/application.rb:11:in `<top (required)>'
# ./config/environment.rb:2:in `<top (required)>'

An error occurred in spec_helper.rb How to debug spec_helper's code which is: spec_helper.rb 中发生错误如何调试 spec_helper 的代码是:

require File.expand_path("../../config/environment", __FILE__)

how to resolve the above error?如何解决上述错误? I'm not sure which gem/file trying to do BigDecimal.new我不确定哪个 gem/file 试图做BigDecimal.new

As suggested by @Tom Lord in the comments updating shoulda matcher to 3.1.3 worked for me正如@Tom Lord 在将should matcher 更新为3.1.3 的评论中所建议的那样为我工作

Requiring config/environment.rb is just loading rails and your app.需要config/environment.rb只是加载 rails 和您的应用程序。 Most likely one of your dependencies is not compatible with ruby 2.6 (for this exact error with BigDecimal.new there's explanation in this answer here , but it is not guaranteed to be the only one), rails by default filters gems from backtraces.很可能您的一个依赖项与 ruby 2.6 不兼容(对于BigDecimal.new的这个确切错误,此处的答案中有解释,但不能保证是唯一的一个),rails 默认情况下会从回溯中过滤宝石。

To debug this you need unfiltered error trace.要调试它,您需要未经过滤的错误跟踪。 To get that you can wrap Bundler.require(*Rails.groups) and Application.initialize!为此,您可以包装Bundler.require(*Rails.groups)Application.initialize! (most likely the error will be in an initializer) with a rescue and get the backtrace from exception directly. (很可能错误将在初始化程序中)通过rescue并直接从异常中获取回溯。

Other approach is to upgrade everything reported by bundle outdated since you're already taking the risk of jumping over multiple rails versions and hope that all used gems already released a compatible version.其他方法是升级bundle outdated报告的所有内容,因为您已经冒着跳过多个 rails 版本的风险,并希望所有使用的 gem 都已经发布了兼容版本。

PS. PS。 usually it's not recommended to skip minor rails and ruby versions during upgrade, because this way you can skip some important deprecations and get unexpected behavior通常不建议在升级过程中跳过次要导轨和 ruby 版本,因为这样您可以跳过一些重要的弃用并获得意外行为

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法启动 Rails 服务器:BigDecimal 的未定义方法“yaml_as”:Class(NoMethodError) - Cannot start rails server: undefined method `yaml_as' for BigDecimal:Class (NoMethodError) NoMethodError:#的未定义方法“类型” <Class> - NoMethodError: undefined method `type' for #<Class> 来自类中Private方法的NoMethodError(未定义方法) - NoMethodError (undefined method) from Private method in class 返回NoMethodError的类方法:未定义的方法Rails - Class method returning NoMethodError: undefined method Rails NoMethodError(未定义方法),但是定义了类方法 - NoMethodError (undefined method) however class method is defined rails 5 NoMethodError in RegistrationsController#new undefined method - rails 5 NoMethodError in RegistrationsController#new undefined method Rails NoMethodError(Hyperclient:Module 的未定义方法“新”) - Rails NoMethodError (undefined method `new' for Hyperclient:Module) NoMethodError(对于LinkedIn:Module,未定义的方法“新”) - NoMethodError (undefined method `new' for LinkedIn:Module) Controller#new中的NoMethodError-未定义的方法 - NoMethodError in controller#new - undefined method “ Revisers#new中的NoMethodError”的未定义方法“输入” - undefined method `input' for “NoMethodError in Revisers#new ”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM