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.1ms) begin transaction
SQL (2.5ms) UPDATE "articles" SET "title" = ?, "updated_at" = ? WHERE "articles"."id" = ? [["title", "New title"], ["updated_at", "2019-05-11 11:51:39.870316"], ["id", 1]]
(1.1ms) 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.1ms) begin transaction
Article Update (2.7ms) UPDATE "articles" SET "title" = ?, "updated_at" = ? WHERE "articles"."id" = ? [["title", "New title"], ["updated_at", "2019-05-11 11:32:48.075786"], ["id", 1]]
(1.1ms) commit transaction
=> true
Removing these methods will break code in many gems as a lot of developers have used update_attributes
over update
.
With this deprecation warning, everyone can start using the preferred way of updating record i.e. update
.
The methods update_attributes
and update_attributes!
will be removed entirely in the next version, Rails 6.1.