Ruby-on-rails 警告:constant ::Fixnum is deprecated 生成新模型时

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/41463999/
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:20  来源:igfitidea点击:

warning: constant ::Fixnum is deprecated When generating new model

ruby-on-railsrubyruby-on-rails-5

提问by user7374147

I've tried to find some solution for this, but I really couldn't find anything related with the errors that is appearing to me when I run the rails command:

我试图为此找到一些解决方案,但我真的找不到与运行 rails 命令时出现的错误相关的任何内容:

rails generate model Book title:string summary:text isbn:string

rails 生成模型书名:字符串摘要:文本 isbn:字符串

/home/vmu/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/activesupport-5.0.1/lib/active_support/xml_mini.rb:51: warning: constant ::Fixnum is deprecated
/home/vmu/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/activesupport-5.0.1/lib/active_support/xml_mini.rb:52: warning: constant ::Bignum is deprecated
/home/vmu/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/activesupport-5.0.1/lib/active_support/core_ext/numeric/conversions.rb:138: warning: constant ::Fixnum is deprecated
Running via Spring preloader in process 3579
Expected string default value for '--jbuilder'; got true (boolean)
      invoke  active_record
   identical    db/migrate/20170104114702_create_books.rb
   identical    app/models/book.rb
      invoke    test_unit
   identical      test/models/book_test.rb
   identical      test/fixtures/books.yml

Anyone know what may be causing these errors?

任何人都知道可能导致这些错误的原因是什么?

采纳答案by IngoAlbers

This warnings appear because you are using ruby 2.4.0.

出现此警告是因为您使用的是 ruby​​ 2.4.0。

This version introduced this change: Unify Fixnum and Bignum into Integer

这个版本引入了这个变化:Unify Fixnum and Bignum into Integer

See here for the announcement: https://www.ruby-lang.org/en/news/2016/12/25/ruby-2-4-0-released/

公告见这里:https: //www.ruby-lang.org/en/news/2016/12/25/ruby-2-4-0-released/

The warnings come from the activesupport gem which is part of rails and will be fixed in an upcoming release.

警告来自 activesupport gem,它是 rails 的一部分,将在即将发布的版本中修复。

For now you can just ignore those warnings.

现在你可以忽略这些警告。

Update:Rails 5.0.2 has been released, which gets rid of the warnings.

更新:Rails 5.0.2 已经发布,消除了警告。

回答by mpalencia

I fixed mine by updating rails

我通过更新 rails 修复了我的

bundle update rails

回答by jvillian

I assume you're using Rails 5? Check out this link(towards the bottom). Looks like these warnings will go away with release #27458.

我假设您使用的是 Rails 5?查看此链接(朝底部)。看起来这些警告将随着版本 #27458 消失。

回答by lsiebert

If these deprecation warnings in active support are the only warnings you are seeing, you can surpress them by passing a RUBYOPT bash variable with the -W0 option which will silence.

如果这些主动支持中的弃用警告是您看到的唯一警告,您可以通过传递带有 -W0 选项的 RUBYOPT bash 变量来抑制它们,这将静音。

so instead of rails servertry: RUBYOPT="-W0" rails serveror RUBYOPT="-W0" bin/rails server

所以不要rails server尝试:RUBYOPT="-W0" rails serverRUBYOPT="-W0" bin/rails server

In rails 5.0 you may want to get in the habit of using bin/rails not just rails, since that's the global rails version which may or may not be the same as your local rails version.

在 rails 5.0 中,您可能希望养成使用 bin/rails 而不仅仅是 rails 的习惯,因为这是全球 rails 版本,它可能与您的本地 rails 版本相同,也可能不同。