Ruby 2.4 和 Rails 4 堆栈级别太深 (SystemStackError)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/41504106/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 08:58:33  来源:igfitidea点击:

Ruby 2.4 and Rails 4 stack level too deep (SystemStackError)

ruby-on-railsruby

提问by coffeina

I'm trying to run newly created project in Rails 4.0.8 but I receive and error:

我正在尝试在 Rails 4.0.8 中运行新创建的项目,但收到错误消息:

    rails s
=> Booting WEBrick
=> Rails 4.0.8 application starting in development on http://0.0.0.0:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
/usr/local/lib/ruby/gems/2.4.0/gems/activesupport-4.0.8/lib/active_support/core_ext/numeric/conversions.rb:121: warning: constant ::Fixnum is deprecated
/usr/local/lib/ruby/gems/2.4.0/gems/activesupport-4.0.8/lib/active_support/core_ext/numeric/conversions.rb:121: warning: constant ::Bignum is deprecated
Exiting
/usr/local/lib/ruby/gems/2.4.0/gems/activesupport-4.0.8/lib/active_support/core_ext/numeric/conversions.rb:124:in `block (2 levels) in <class:Numeric>': stack level too deep (SystemStackError)
    from /usr/local/lib/ruby/gems/2.4.0/gems/activesupport-4.0.8/lib/active_support/core_ext/numeric/conversions.rb:131:in `block (2 levels) in <class:Numeric>'
    from /usr/local/lib/ruby/gems/2.4.0/gems/activesupport-4.0.8/lib/active_support/core_ext/numeric/conversions.rb:131:in `block (2 levels) in <class:Numeric>'
    from /usr/local/lib/ruby/gems/2.4.0/gems/activesupport-4.0.8/lib/active_support/core_ext/numeric/conversions.rb:131:in `block (2 levels) in <class:Numeric>'
    from /usr/local/lib/ruby/gems/2.4.0/gems/activesupport-4.0.8/lib/active_support/core_ext/numeric/conversions.rb:131:in `block (2 levels) in <class:Numeric>'
    from /usr/local/lib/ruby/gems/2.4.0/gems/activesupport-4.0.8/lib/active_support/core_ext/numeric/conversions.rb:131:in `block (2 levels) in <class:Numeric>'
    from /usr/local/lib/ruby/gems/2.4.0/gems/activesupport-4.0.8/lib/active_support/core_ext/numeric/conversions.rb:131:in `block (2 levels) in <class:Numeric>'
    from /usr/local/lib/ruby/gems/2.4.0/gems/activesupport-4.0.8/lib/active_support/core_ext/numeric/conversions.rb:131:in `block (2 levels) in <class:Numeric>'
    from /usr/local/lib/ruby/gems/2.4.0/gems/activesupport-4.0.8/lib/active_support/core_ext/numeric/conversions.rb:131:in `block (2 levels) in <class:Numeric>'
     ... 5532 levels...
    from /usr/local/lib/ruby/gems/2.4.0/gems/railties-4.0.8/lib/rails/commands.rb:71:in `tap'
    from /usr/local/lib/ruby/gems/2.4.0/gems/railties-4.0.8/lib/rails/commands.rb:71:in `<top (required)>'
    from bin/rails:4:in `require'
    from bin/rails:4:in `<main>'

Ruby version:

红宝石版本:

Rails 4.0.8

My Gemefile:

我的 Gemefile:

source 'https://rubygems.org'

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.0.8'

# Use sqlite3 as the database for Active Record
gem 'sqlite3'

# Use SCSS for stylesheets
gem 'sass-rails', '~> 4.0.2'

# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'

# Use CoffeeScript for .js.coffee assets and views
gem 'coffee-rails', '~> 4.0.0'

# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby

# Use jquery as the JavaScript library
gem 'jquery-rails'

# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'

# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 1.2'
gem 'json', github: 'flori/json', branch: 'v1.8'
group :doc do
  # bundle exec rake doc:rails generates the API under doc/api.
  gem 'sdoc', require: false
end

I tried to reinstall rails because before I have 5.0 Rails installed on my machine.

我尝试重新安装 rails,因为在我的机器上安装了 5.0 Rails 之前。

Local gems:

本地宝石:

*** LOCAL GEMS ***

autoprefixer-rails (6.6.0)
coffee-rails (4.2.1, 4.0.1)
font-awesome-rails (4.7.0.1)
jquery-atwho-rails (1.3.2)
jquery-rails (4.2.2, 3.1.4)
rails (4.0.8, 4.0.0)
rails-dom-testing (2.0.2)
rails-html-sanitizer (1.0.3)
rails_12factor (0.0.3)
rails_serve_static_assets (0.0.5)
rails_stdout_logging (0.0.5)
sass-rails (5.0.6, 4.0.5)
sprockets-rails (3.2.0, 2.3.3, 2.0.1)

Meybe unistall: ruby and rails will solve this problem, but I dont want to do that. Beasically I whant to have installed both version of rails, for exampole: rails 4 and rails 5 as well. Is that configuration possible ?

Meybe unistall:ruby 和 rails 会解决这个问题,但我不想那样做。Beasically 我想要安装两个版本的导轨,例如:导轨 4 和导轨 5。这种配置可以吗?

回答by Holger Just

In Ruby 2.4, there was a unification of integer types (i.e. Fixnumand Bignumare now the very same thing: Integer). This results on quite a few incompatibilities with existing gems which relied on the distinction of the classes.

在 Ruby 2.4 中,统一了整数类型(即FixnumBignum现在是完全相同的东西:)Integer。这导致了与依赖于类别区别的现有 gem 的相当多的不兼容。

Older versions of ActiveSupport are among those which don't like this unification and barf over it when trying to serialize data. As such, you have one of two options:

旧版本的 ActiveSupport 是那些不喜欢这种统一并在尝试序列化数据时对它嗤之以鼻的人之一。因此,您有以下两种选择之一:

  • You can downgrade Ruby to a version earlier than 2.4, e.g. Ruby 2.3.x.
  • Or you could upgrade Rails to a newer version. Preferably, that could be Rails 5.x. There is also a patch in the 4.2-stable branch which was released with Rails 4.2.8, making it the first version of the Rails 4.2 series that officially supports Ruby 2.4. Earlier Rails versions are not compatible with Ruby 2.4.
  • 您可以将 Ruby 降级到 2.4 之前的版本,例如 Ruby 2.3.x。
  • 或者您可以将 Rails 升级到更新的版本。最好是 Rails 5.x。在Rails 4.2.8发布的 4.2-stable 分支中还有一个补丁,使其成为正式支持 Ruby 2.4 的 Rails 4.2 系列的第一个版本。较早的 Rails 版本与 Ruby 2.4 不兼容。

回答by Зелёный

I have the same error, but I don't want to upgrade to 5.0, my app is very big and upgrate take too many time. I'm upgrading the Rails 4.1.7to the Rails to 4.2.8first Rails release with Ruby 2.4support:

我有同样的错误,但我不想升级到 5.0,我的应用程序非常大,升级需要太多时间。我正在升级Rails 4.1.7到第Rails to 4.2.8一个 Rails 版本的Ruby 2.4支持:

in the Gemfile:

在 Gemfile 中:

gem 'rails', '4.2.8'

Then:

然后:

bundle update rails

回答by Зелёный

In regards to the error, you're running the just-released Ruby 2.4, which Rails and ActiveSupport (especially older versions of these) most likely don't support yet.

关于错误,您正在运行刚刚发布的 Ruby 2.4,Rails 和 ActiveSupport(尤其是这些的旧版本)很可能还不支持。

ThisRails guide states your Rails version (4.0.8) prefers Ruby 2.0.

Rails 指南指出您的 Rails 版本 (4.0.8) 更喜欢 Ruby 2.0。

You can fix the error by either upgrading your Rails installation (gem 'rails', '5.0') or downgrading to an older version of Ruby with a version manager (e.g. $ rvm install 2.3.0; rvm use 2.3.0).

您可以通过升级 Rails 安装 ( gem 'rails', '5.0') 或使用版本管理器 (例如$ rvm install 2.3.0; rvm use 2.3.0)降级到旧版本的 Ruby来修复错误。