We use
update_attribute
It updates the single attribute with bypassing the validations.
update_column
It updates the single attribute with bypassing the validations as well as the callbacks.
Model.update_attribute :field, 'value' Model.update_column :field, 'value'
In case if you need to use
module ActiveRecord module AttributeMethods def update_column(name, value) name = name.to_s self.class.update_all({ name => value }, self.class.primary_key => id) == 1 end end end
Related posts:
Difference between update_attribute and update_column
What is different in update_all, update, update_attribute, update_attributes methods of Active Record
Difference between .nil?, .empty?, .blank?, .present?
render vs redirect_to in Ruby on Rails
About
No comments:
Post a Comment