Rails 6 deprecates update_attributes and update_attributes!

1 minute read

ActiveRecord#update and ActiveRecord#update! were added as aliases for update_attributes and update_attributes! in Rails 4 This soft deprecation was added to align with other Active Record methods like create and provide better semantics when a resource is being updated. Using update_attributes didn’t give any deprecation warning until Rails 5.2.

Rails 6 deprecates update_attributes and update_attributes! in favour of update and update! and we can now see deprecation warning when invoked.

Before Rails 6

> article . update_attributes ( title: 'New title' ) ( 0.1 ms ) begin transaction SQL ( 2.5 ms ) UPDATE "articles" SET "title" = ?, "updated_at" = ? WHERE "articles" . "id" = ? [[ "title" , "New title" ], [ "updated_at" , "2019-05-11 11:51:39.870316" ], [ "id" , 1 ]] ( 1.1 ms ) commit transaction => true

In Rails 6

> article . update_attributes ( title: 'New title' ) DEPRECATION WARNING : update_attributes is deprecated and will be removed from Rails 6.1 ( please , use update instead ) ( 0.1 ms ) begin transaction Article Update ( 2.7 ms ) UPDATE "articles" SET "title" = ?, "updated_at" = ? WHERE "articles" . "id" = ? [[ "title" , "New title" ], [ "updated_at" , "2019-05-11 11:32:48.075786" ], [ "id" , 1 ]] ( 1.1 ms ) commit transaction => true