66

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**

I saw this link and there are some suggestion to switch of warnings like "If you want to disable the deprecation warnings, please use a command-line argument -W:no-deprecated or add Warning[:deprecated] = false to your code." but I was thinking on little bit better solution/fix for actionpack v6.0.2.1

NoDataDumpNoContribution
  • 10,591
  • 9
  • 64
  • 104
Nezir
  • 6,727
  • 12
  • 54
  • 78
  • 9
    Positional arguments and keyword arguments are to be separated in Ruby 3.0. This is a mere warning. Rails is filled with this pattern. https://www.ruby-lang.org/en/news/2019/12/12/separation-of-positional-and-keyword-arguments-in-ruby-3-0/ – Josh Brody Dec 26 '19 at 18:30
  • 4
    @JoshBrody thank you very much. I saw this link and there are some suggestion to switch of warnings like "If you want to disable the deprecation warnings, please use a command-line argument -W:no-deprecated or add Warning[:deprecated] = false to your code." but I was thinking on little bit better solution/fix for actionpack v6.0.2.1 – Nezir Dec 27 '19 at 07:42
  • 1
    Hiding deprecation warnings across the board is a BAD idea, especially when you want to smooth out your future upgrades. – Vlad Feb 19 '20 at 15:58
  • 2
    @Vlad agreed but reducing log noise temporarily is ok (if you know what you're doing) – Khalil Gharbaoui Mar 02 '20 at 13:04

3 Answers3

80

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-

Khalil Gharbaoui
  • 6,557
  • 2
  • 19
  • 26
  • 2
    One issue with this is that installed previous versions of Ruby where the -W:no-deprecated' flag is not valid will throw an error. I fixed this by using export RUBYOPT='-W0' – Augusto Samamé Barrientos Feb 15 '20 at 10:15
  • Is there a way of calling the task that won't give a warning, i.e. to call it in a way that isn't deprecated? – barlop Apr 22 '20 at 12:14
  • @barlop well it's not the task that is giving the warning. The warnings come from the underlying code. Basically finding the deprecations if they are in your own code and fixing them will do. And if they are not part of your code then open issues or pull requests on the repos of the gems you are including and ask them for a fix. or just wait for them to fix it. Some deprecations are mentioned here: https://www.ruby-lang.org/en/news/2019/12/25/ruby-2-7-0-released/ and here: https://rubyreferences.github.io/rubychanges/2.7.html – Khalil Gharbaoui Apr 22 '20 at 18:00
  • @KhalilGharbaoui Thanks. I just did.a fresh insall of ruby and rails iirc https://pastebin.com/SYjypsrP looks like i have the latest of each and all I did was created a blank project, tried rake help and got the warning also with rails db:migrate. I guess I should go on those repos. rake about mentions actionpack. rake db:migrate or rails db:migrate mentions actionpack, activerecord, activemodel. Though aren't some of those even native to rails so strange that the rails people couldn't get it right. – barlop Apr 22 '20 at 23:15
  • You shouldn't suppress the warnings, just update to the most recent Rails version. – iGEL Dec 18 '20 at 12:01
14

Update to Rails 6.0.3, they fixed the warnings.

If you still get warnings, it's other libraries (see if there are fixed versions or submit a patch) or your own code (how to fix it).

iGEL
  • 16,540
  • 11
  • 60
  • 74
  • How do I fix this in Rails 5? The latest Rails 5 version still has the warning. – morgler Dec 30 '20 at 14:07
  • 1
    @morgler As stated in [Rails maintenance policy](https://guides.rubyonrails.org/maintenance_policy.html#bug-fixes), by now only Rails 6.1 will receive bug fixes. Either you update to Rails 6.0.3 or higher, you fork and fix the warnings yourself or find an existing fork, you live with the warnings or you hide them as suggested by the other answers. – iGEL Jan 01 '21 at 15:19
  • I get the warnings on `Rails 6.0.3.2` – stevec Jan 24 '21 at 09:57
  • 1
    @stevec It's most likely your own code or some other library causing the warnings. Rails has been fixed – iGEL Jan 25 '21 at 12:21
  • I am using rails 6.0.3.6, still getting the warning as '/Users/***/.rvm/gems/ruby-2.7.2/gems/json-1.8.6/lib/json/common.rb:155: warning: Using the last argument as keyword parameters is deprecated' – honey Apr 05 '21 at 06:38
  • @devsat Read the previous comment. – iGEL Apr 06 '21 at 08:25
6

Obviously it will take some time to for ruby team to remove all this warning in next ruby version. For now the command in your terminal

`RUBYOPT='-W:no-deprecated' rails s` 

on my basic, plain new rails 6.0.2.1 && ruby 2.7.0 project remove these two warnings lines above in a question.

Also, with command

RUBYOPT='-W:no-experimental' rails s

you will hide warnings about experimental features.

You can combine these two in one command like:

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

However, I tried these commands inside my old project built with rails 5.2 and ruby 2.6.4 later upgraded to rails 6.0.1 and they didn't worked well on for all warnings messages I got from different rails Active* modules and ruby gems.

Probably we will need some time for upgrading code and gems for new latest stuff.

Nezir
  • 6,727
  • 12
  • 54
  • 78
  • This doesn't seem to have any effect in Rails 6.1 with Ruby 2.7.2. I still see the warnings: `.rvm/gems/ruby-2.7.2/gems/json-1.8.6/lib/json/common.rb:155: warning: Using the last argument as keyword parameters is deprecated` – mansoor.khan Apr 23 '23 at 14:25