How to fix Rails's warning messages with Ruby 2.7.0

Nezir picture Nezir · Dec 26, 2019 · Viewed 24.6k times · Source

Did anyone resolve this issue with Ruby 2.7.0?

I used rbenv and installed Ruby v2.7.0 and then created a Rails project using Rails v6.0.2.1.

Currently, by running one of

rails s
rails s -u puma
rails s -u webrick

the server is up and the site is served but in the Console log I see two warning messages:

local:~/rcode/rb27$ rails s
=> Booting Puma
=> Rails 6.0.2.1 application starting in development 
=> Run `rails server --help` for more startup options
.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/actionpack-6.0.2.1/lib/action_dispatch/middleware/stack.rb:37: warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call
.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/actionpack-6.0.2.1/lib/action_dispatch/middleware/static.rb:110: warning: The called method `initialize' is defined here
Puma starting in single mode...
* Version 4.3.1 (ruby 2.7.0-p0), codename: Mysterious Traveller
* Min threads: 5, max threads: 5
* Environment: development
* Listening on tcp://127.0.0.1:3000
* Listening on tcp://[::1]:3000 

So, the warning messages are:

**.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/actionpack-6.0.2.1/lib/action_dispatch/middleware/stack.rb:37: warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call**

**.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/actionpack-6.0.2.1/lib/action_dispatch/middleware/static.rb:110: warning: The called method `initialize' is defined here**

Answer

Khalil Gharbaoui picture Khalil Gharbaoui · Jan 4, 2020

To suppress warnings like:

warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call

For now, simply prefix/pass the RUBYOPT environment variable to your rails commands:

RUBYOPT='-W:no-deprecated -W:no-experimental' rails server
or
RUBYOPT='-W:no-deprecated -W:no-experimental' rails db:migrate

This may not work with earlier versions of ruby.

For backward compatibility with earlier versions of ruby prefix it with RUBYOPT='-W0' instead.

example:

RUBYOPT='-W0' bundle exec rspec

If you don't want to prefix this each time you run a command, then simply add this to the last line of your .zshrc or .bashrc (whatever you're using):

export RUBYOPT='-W:no-deprecated -W:no-experimental'
or
export RUBYOPT='-W0'

Also see last point of the notes here:
https://rubyreferences.github.io/rubychanges/2.7.html#warning-and-