How to update a column directly in Database in Ruby on Rails

In order to update a field there are many methods in Rails. But, to update a field in Database directly you should be using update_column or update_columns.

update_column

update_column( :field_name, field_value )
  • It doesn’t validate the record.
  • It doesn’t call callbacks.
  • It doesn’t call save method.

Thus, updates the record in Database directly by not going through regular update procedures.

update_columns

update_columns( field_name: field_value )
  • It doesn’t validate the record.
  • It doesn’t call callbacks.
  • It doesn’t call save method.
  • It works for version above 3 in Rails.

Keep Coding !!!

Ameena