Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using update_columns in Rails 3?

Is there a shorter way for this in Rails 3?

user.update_column(:attribute1, value1)
user.update_column(:attribute2, value2)
user.update_column(:attribute3, value3)
user.update_column(:attribute4, value4)

I tried update_columns but it's only available in Rails 4.

Thanks for any help.

like image 220
Tintin81 Avatar asked Aug 17 '13 16:08

Tintin81


1 Answers

Here's a workaround for Rails 3.x:

User.where(id: user.id).update_all(attribute1: value1, attribute2: value2, ...)
like image 80
ndbroadbent Avatar answered Oct 14 '22 15:10

ndbroadbent