LoginSignup
8
7

More than 3 years have passed since last update.

【Rails6】DEPRECATION WARNING: update_attributes is deprecated and will be removed from Rails 6.1 (please, use update instead)

Posted at

TL;DR

update_attributes => update に変更しましょう。
※安心してください。動作は変わりません。

環境

  • Ruby: 2.6.3
  • Rails: 5.2.4.1 => 6.0.2.1 へアップデート

なんかWarning出たな? :thinking:

DEPRECATION WARNING: update_attributes is deprecated and will be removed from Rails 6.1 (please, use update instead)

update_attributes, update_attributes! を使っているところでこんなWarningが出ました。

update_attributes は Rails 6.1 で削除するから、代わりに update を使ってねって言われています。

変更しちゃって大丈夫? :thinking:

Railsのソースを見てみましょう。
https://github.com/rails/rails/blob/v6.0.2.1/activerecord/lib/active_record/persistence.rb#L625

alias update_attributes update
deprecate update_attributes: "please, use update instead"

update_attributesupdate のaliasとして定義されています。
なので、どちらを使っても動作は変わらないです。

update_attributes! も同様ですね。
https://github.com/rails/rails/blob/v6.0.2.1/activerecord/lib/active_record/persistence.rb#L639-L640

ガッと update, update! へ変更してWarning解消出来ました。

8
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
7