I have a model called Agency
One of the row from Agency active record looks as follows:
#<Agency id: 1, name: "Hello", contact_person: "Abhimanyu", phone_number: "946159", email: "[email protected] ", local_package: false, outstation: true, remarks: nil, status: 1>
Here I want to change the value of status
to 0
. How can I do that ?
Rails provides many method for update an activerecord. You can get differences of each method from this blog
agency = Agency.find(1)
update
agency.update(status: 0)
update_attribute
agency.update_attribute(:status, 0)
update_column
agency.update_column(:status, 0)
update_columns
agency.update_columns(status: 0)
You can also use this
Agency.find(1).update_column(:status, 0)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With