Tuesday, 15 February 2011

How to update multiple columns in Ruby on Rails 3? -



How to update multiple columns in Ruby on Rails 3? -

just out of curiosity, there way this...

user.update_column(:field1, true) user.update_column(:field2, true)

... in 1 line in ruby on rails?

as far know update_columns method not exist...

you can utilize update_all follows:

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

this generate next update statement (mysql):

update users set field1 = 1, field2 = 1 users.id = <whatever>

callbacks , validations not run.

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

No comments:

Post a Comment