how can I update a table Notification.email to all true in console?
In console, I'd like to loop through all the records in the table and set email = true.
Ideas?
this should work
Notification.all.each do |n| n.update_attribute(:email, true); end
edit: made custom from bricker:
Notification.all.each { |n| n.update_attribute(:email, true) }
You're looking for update_all
. See doc.
Beware, no callbacks are triggered this way.
You can use:
Notification.update_all(email: true)
If you additionally have a condition while updating you should use:
Notification.find_each { |n| n.email = (n.id > 100) ? true : false }
Use Something.all
is bad idea for huge db table.
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