【Rails6】update_attributesが非推奨になっていた件
- 2020.04.18
- プログラミング学習
- Ruby on Rails

Railsチュートリアルを元にwebアプリを作っていた際に気になる警告が出た。
警告が出たのはこのコード
def update
if @user.update_attributes(user_params)
flash[:success] = "Profile updated"
redirect_to @user
else
render 'edit'
end
end
警告が出ていたログ
DEPRECATION WARNING: update_attributes is deprecated and will be removed from Rails 6.1 (please, use update instead)
非推奨の警告:update_attributesは非推奨であり、Rails6.1から消去されます。(代わりにupdateを使用してください)
調べてみると、Ruby on Rails 6.0 リリースノートにちゃんと書かれていた。

update_attributesもしくはupdate_attributes!を非推奨とし、updateもしくはupdate!を用いる。(そのまま)
下記のように書き換えて解決。
def update
# if @user.update_attributes(user_params)
if @user.update(user_params)
flash[:success] = "Profile updated"
redirect_to @user
else
render 'edit'
end
end
