Looking for Ruby on Rails development company?
Contact Us

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

How to update a column directly in Database in Ruby on Rails using update_column and update_columns. This is useful when you don't want to invoice Rails validations, callbacks and want to push the data directly to database.

Posted by Ameena on 04 Sep 2017
How to update a column directly in Database | 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


Looking for Ruby on Rails development company?
Contact Us

Related Services.



Hire ReactJS Developers
Hire Gatsby Developers
Hire NextJS Developers

We support the Open Source community.



Have a Project in mind?