DEV Community

Cover image for Hiding Ruby 2.7 Deprecation Warnings in Rails 6

Hiding Ruby 2.7 Deprecation Warnings in Rails 6

Andrew Mason on February 06, 2020

Hiding Ruby 2.7 Deprecation Warnings in Rails 6 If you have upgraded your Rails app to Ruby 2.7, you are probably seeing a lot of deprec...
Collapse
 
woto profile image
Ruslan Kornev

Hi Andrew, i've cloned your repository and still got warnings. What I'm doing wrong?

[1] pry(main)> Post.first
/Users/r.kornev/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/activemodel-6.0.2.1/lib/active_model/type/integer.rb:13: warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call
/Users/r.kornev/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/activemodel-6.0.2.1/lib/active_model/type/value.rb:8: warning: The called method `initialize' is defined here
/Users/r.kornev/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/activerecord-6.0.2.1/lib/active_record/connection_adapters/postgresql/oid/specialized_string.rb:12: warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call
/Users/r.kornev/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/activemodel-6.0.2.1/lib/active_model/type/value.rb:8: warning: The called method `initialize' is defined here
  Post Load (1.0ms)  SELECT "posts".* FROM "posts" ORDER BY "posts"."id" ASC LIMIT $1  [["LIMIT", 1]]
=> nil
Collapse
 
chrislewis60 profile image
Chris Lewis

You can also choose to have depreciation warnings sent to the log file rather than printed out to the console. For example, in the test environment, add the following to config/environments/test.rb

config.active_support.deprecation = :log
Enter fullscreen mode Exit fullscreen mode
Collapse
 
limeblast profile image
Daniel Hollands

The string -W:no-deprecated -W:no-experimental didn't work for me, but -W0 did, which I found at stackoverflow.com/a/59594760/1049688

Collapse
 
michelegera profile image
Michele Gerarduzzi

On method #1 (using dotenv-rails), the line to add to .env should read:

RUBYOPT='-W:no-deprecated -W:no-experimental'

as the dotenv-rails gem will take care to export it.

Collapse
 
leesmith profile image
Lee Smith 🍻

So this is just to silence them within ruby? Won’t rails internals eventually knock out these warnings?

Collapse
 
andrewmcodes profile image
Andrew Mason

They will but this will help until that update lands!

Collapse
 
waynehoover profile image
Wayne

None of these worked for me.

Collapse
 
andrewmcodes profile image
Andrew Mason

Did you reload your zshrc/bashrc or reload your terminal?