BigBinary Blog

We write about Ruby on Rails, React.js, React Native, remote work, open source, engineering and design.

Rails 6 raises ActiveModel::MissingAttributeError

This blog is part of our Rails 6 series.

Rails 6.0 was recently released.

Rails 6 raises ActiveModel::MissingAttributeError when update_columns is used with a non-existing attribute. Before Rails 6, update_columns raised an ActiveRecord::StatementInvalid error.

Rails 5.2

1
2> > User.first.update_columns(email: 'amit@bigbinary.com')
3> > SELECT "users".\* FROM "users" ORDER BY "users"."id" ASC LIMIT $1  [["LIMIT", 1]]
4UPDATE "users" SET "email" = $1 WHERE "users"."id" = \$2 [["email", "amit@bigbinary.com"], ["id", 1]]
5
6=> Traceback (most recent call last):
71: from (irb):8
8ActiveRecord::StatementInvalid (PG::UndefinedColumn: ERROR: column "email" of relation "users" does not exist)
9LINE 1: UPDATE "users" SET "email" = $1 WHERE "users"."id" = $2
10^
11: UPDATE "users" SET "email" = $1 WHERE "users"."id" = $2

Rails 6.0.0.beta2

1
2> > User.first.update_columns(email: 'amit@bigbinary.com')
3> > SELECT "users".\* FROM "users" ORDER BY "users"."id" ASC LIMIT ? [["LIMIT", 1]]
4
5Traceback (most recent call last):
61: from (irb):1
7ActiveModel::MissingAttributeError (can't write unknown attribute `email`)

Here is the relevant commit.

Amit Choudhary in Rails 6
March 20, 2019
Share

Subscribe to our newsletter