How to update multiple columns in Ruby on Rails 3?

ruby, ruby-on-rails-3, ruby-on-rails-3.2

Solution

You can use `update_all` as follows:

User.where(:id => user.id).update_all({:field1 => true, :field2 => true})

This will generate the following update statement (mysql):

UPDATE users SET field1 = 1, field2 = 1 WHERE users.id = <whatever>

Callbacks and validations will not be run.

Problem

Just out of curiosity, is there a way to say this... ``` user.update_column(:field1, true) user.update_column(:field2, true) ``` ... in one line in Ruby on Rails? As far as I know an `update_columns` method does not exist...

Original source

Related problems