[ruby-on-rails] Ruby 2.7.0으로 Rails의 경고 메시지를 수정하는 방법

누구든지이 문제를 해결 했습니까 Ruby 2.7.0?

rbenvRuby v2.7.0을 사용 하고 설치 한 다음을 사용하여 Rails 프로젝트를 작성했습니다 Rails v6.0.2.1.

현재 중 하나를 실행하여

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

서버가 작동 중이고 사이트가 제공되었지만 Console로그에 두 가지 경고 메시지가 표시됩니다.

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 

따라서 경고 메시지는 다음과 같습니다.

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



답변

다음과 같은 경고를 표시하지 않으려면

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

지금은 RUBYOPT환경 변수를 rails 명령에 접두사 / 전달하면 됩니다 :

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

이전 버전의 루비에서는 작동하지 않을 수 있습니다.

이전 버전의 루비 접두사와의 호환성을 위해 RUBYOPT='-W0'대신에 접두사를 붙 입니다.

예:

RUBYOPT='-W0' bundle exec rspec

명령을 실행할 때마다이 접두사를 사용하지 않으려면 .zshrc또는 마지막 줄 .bashrc( 또는 사용중인 항목)에 추가하십시오.

export RUBYOPT='-W:no-deprecated -W:no-experimental'
또는
export RUBYOPT='-W0'

https://rubyreferences.github.io/rubychanges/2.7.html#warning-and- 참고 사항의 마지막 지점도 참조하십시오.


답변

분명히 루비 팀이 다음 루비 버전에서이 모든 경고를 제거하는 데 시간이 걸릴 것입니다. 지금은 터미널에서 명령

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

내 기본적이고 평범한 새 레일 6.0.2.1 및 & ruby ​​2.7.0 프로젝트에서 위의 두 경고 라인을 문제에서 제거합니다.

또한 명령으로

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

실험 기능에 대한 경고를 숨길 수 있습니다.

이 두 가지를 하나의 명령으로 결합 할 수 있습니다 :

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

그러나 레일 5.2 및 루비 2.6.4로 빌드 된 이전 프로젝트 에서이 명령을 나중에 레일 6.0.1로 업그레이드했지만 다른 레일 Active * 모듈 및 루비 보석에서 얻은 모든 경고 메시지에 대해서는 제대로 작동하지 않았습니다.

아마도 우리는 새로운 최신 물건을 위해 코드와 보석을 업그레이드하는 데 약간의 시간이 필요할 것입니다.


답변

경고 일 뿐이며 아무런 영향을 미치지 않습니다. 간단히 억제 할 수 있습니다. 솔루션 2가 나에게 맞는 것으로 나타났습니다.

옵션 1. 다음과 같이 레일 서버를 시작하십시오. RUBYOPT='-W:no-deprecated' rails s

옵션 2. export RUBYOPT='-W:no-deprecatedbash / zsh 프로파일에서 설정

옵션 3. Warning[:deprecated] = false루비 코드로 설정


답변